docker image —— x86 转 arm64

1.下载qemu
wget https://github.com/multiarch/qemu-user-static/releases/download/v5.1.0-2/qemu-aarch64-static.tar.gz
tar -zxvf qemu-aarch64-static.tar.gz -C /usr/bin/
2.启动qemu
docker run --rm --privileged multiarch/qemu-user-static:register
3.使用
例子
docker run --name C_ARM_MIDDLE  -id -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static -v /tmp:/tmp $ARM_BASIC  cp /tmp/ROOT.war /usr/local/tomcat/webapps

4.将x86架构的镜像,转换为arm64架构支持

#!/bin/bash
set -e
DIR_PATH=$(cd "$(dirname "$0")"; pwd)
cat $DIR_PATH/images | grep "set -e ; bin/catalina.sh run" > $DIR_PATH/images_update
#cat $DIR_PATH/images.org  > $DIR_PATH/images_update
# Linux
sed -i  's#registry.bizsaas.net#registry.bizsaas.net/arm64v8#g'  $DIR_PATH/images_update
sed -i "s/\t/|/g" $DIR_PATH/images_update
# macOS
# pass     sed -i "" 's/registry.bizsaas.net/registry.bizsaas.net\/arm64v8/g' $DIR_PATH/images_update
# not pass sed -i "" "s//|/g" $DIR_PATH/images_update
cat $DIR_PATH/images_update | while read line
do
  echo "line:" $line
  ARM_IMAGE=""
  ARM_BASIC=""
  OPER=""
  START_CMD=""
  #not pass: eval $(echo $line | awk -F "|" '{printf("ARM_IMAGE=%s;OPER=%s;START_CMD=%s;ARM_BASIC=%s",$1,$2,$3,$4)}')
  eval $(echo $line | awk -F "|" '{printf("ARM_IMAGE=%s;OPER=%s;ARM_BASIC=%s",$1,$2,$4)}')
  START_CMD=$(echo $line | awk -F "|" '{print $3}')
  X86_IMAGE=`echo $ARM_IMAGE | sed -e 's/\/arm64v8//g'`
  echo "X86_IMAGE:" $X86_IMAGE
  echo "ARM_IMAGE:" $ARM_IMAGE
  echo "ARM_BASIC:" $ARM_BASIC

  echo "START_CMD:" $START_CMD
  echo "OPER:" $OPER


  docker pull $X86_IMAGE
  docker pull $ARM_BASIC

  docker run --name C_X86 -v /tmp:/tmp  -i  $X86_IMAGE cp /usr/local/tomcat/webapps/ROOT.war /tmp
  docker rm -f C_X86

# arm support
# macos passed  docker run --name C_ARM_MIDDLE  -id -v /tmp:/tmp $ARM_BASIC  cp /tmp/ROOT.war /usr/local/tomcat/webapps

  docker run --name C_ARM_MIDDLE  -id -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static -v /tmp:/tmp $ARM_BASIC  cp /tmp/ROOT.war /usr/local/tomcat/webapps
  docker commit C_ARM_MIDDLE  image_arm_middle:latest
  docker rm -f C_ARM_MIDDLE

# arm support
#  docker run --name C_ARM -d -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static image_arm_middle:latest /bin/sh -c "$START_CMD"
  docker run --name C_ARM -d -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static image_arm_middle:latest /usr/local/tomcat/bin/catalina.sh run
  docker commit C_ARM $ARM_IMAGE
  docker rm -f C_ARM

#  docker push $ARM_IMAGE

  rm -f /tmp/ROOT.war
  docker rmi $X86_IMAGE $ARM_BASIC image_arm_middle:latest
  echo "ARM_IMAGE:" $ARM_IMAGE
done

 

你可能感兴趣的:(shell)