需求
项目需要提供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
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镜像文章来源:https://www.toymoban.com/news/detail-502590.html
about
欢迎关注我的博客文章来源地址https://www.toymoban.com/news/detail-502590.html
到了这里,关于x86架构上构建arm64架构的docker镜像的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!