x86架构上构建arm64架构的docker镜像

需求

项目需要提供arm64架构上的centos7对应docker镜像,然后本地宿主机只有x86架构机器,因此需要在x86机器上构建centos arm64架构的docker镜像

环境

宿主机操作系统:centos7.7 amd64架构
docker版本:19.03.15

镜像构建

拉取arm64版本centos7

docker pull centos:7.9.2009 --platform=arm64
# 通过命令查询镜像信息
docker inspect centos:7.9.2009

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Og0bs1ac-1662349203615)(/upload/2022/05/image-1653533151159.png)]

ARM,AMD,X86,AArch64的概念可以参考:
https://blog.csdn.net/Bubbler_726/article/details/88397357

qemu配置

下载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

运行arm容器

docker run -it -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static centosarm架构镜像id

启动成功后自动进入容器内

arm架构容器内安装软件

首先配置国内yum源

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

x86架构上构建arm64架构的docker镜像

猜你喜欢

转载自blog.csdn.net/HYESC/article/details/126701828