项目需要提供arm64架构上的centos7对应docker镜像,然后本地宿主机只有x86架构机器,因此需要在x86机器上构建centos arm64架构的docker镜像
宿主机操作系统:centos7.7 amd64架构
docker版本:19.03.15
docker pull centos:7.9.2009 --platform=arm64
# 通过命令查询镜像信息
docker inspect centos:7.9.2009
ARM,AMD,X86,AArch64的概念可以参考:
https://blog.csdn.net/Bubbler_726/article/details/88397357
下载qemu-aarch64-static.tar.gz
# 下载
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
# 移动到/usr/bin
mv qemu-aarch64-static /usr/bin
#拉取qemu-user-static镜像
docker pull multiarch/qemu-user-static:register
启动qemu
docker run --rm --privileged multiarch/qemu-user-static:register
docker run -it -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static centosarm架构镜像id
启动成功后自动进入容器内
cp /etc/yum.repo.d{,.bak} # 备份原有yum源文件
rm -rf /etc/yum.repo.d/* # 清空原有yum源文件
cd /etc/yum.repo.d
vim CentOS-Base.repo
添加如下内容,注意是阿里源,同时设置gpgcheck=0
,默认是1,但是会报错,报错内容大概如下:
The GPG keys listed for the "CentOS-7 - Base" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
Failing package is: perl-threads-1.87-4.el7.aarch64
GPG Keys are configured as: https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
取消gpgcheck
验证避免该问题的出现,无论如何变更gpgkey地址,都是总会报错,因此直接设置gpgcheck=0更直接省事。
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.aliyun.com/centos-altarch/$releasever/os/$basearch/
gpgcheck=0
gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-7-aarch64
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.aliyun.com/centos-altarch/$releasever/updates/$basearch/
gpgcheck=0
gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-7-aarch64
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.aliyun.com/centos-altarch/$releasever/extras/$basearch/
gpgcheck=0
gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-7-aarch64
enabled=1
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.aliyun.com/centos-altarch/$releasever/centosplus/$basearch/
gpgcheck=0
enabled=0
gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-7-aarch64
设置之后使用yum下载软件后打包镜像即可
docker commit container_id centos-arm:7.9
更多docker commit命令参考 https://www.runoob.com/docker/docker-commit-command.html