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
1
2
3
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
1
2
3
4
5
6
7
8
9
启动qemu
docker run --rm --privileged multiarch/qemu-user-static:register
1
运行arm容器
docker run -it -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static centosarm架构镜像id
1
启动成功后自动进入容器内
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
1
2
3
4
添加如下内容,注意是阿里源,同时设置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
1
2
3
4
5
取消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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
设置之后使用yum下载软件后打包镜像即可
打包容器为镜像
docker commit container_id centos-arm:7.9
1
更多docker commit命令参考 https://www.runoob.com/docker/docker-commit-command.html
x86架构上构建arm64架构的docker镜像
————————————————
版权声明:本文为CSDN博主「he-yin」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/HYESC/article/details/126701828