需求
項(xiàng)目需要提供arm64架構(gòu)上的centos7對(duì)應(yīng)docker鏡像,然后本地宿主機(jī)只有x86架構(gòu)機(jī)器,因此需要在x86機(jī)器上構(gòu)建centos arm64架構(gòu)的docker鏡像
環(huán)境
宿主機(jī)操作系統(tǒng):centos7.7 amd64架構(gòu)
docker版本:19.03.15
鏡像構(gòu)建
拉取arm64版本centos7
docker pull centos:7.9.2009 --platform=arm64
# 通過(guò)命令查詢鏡像信息
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
# 移動(dòng)到/usr/bin
mv qemu-aarch64-static /usr/bin
#拉取qemu-user-static鏡像
docker pull multiarch/qemu-user-static:register
啟動(dòng)qemu
docker run --rm --privileged multiarch/qemu-user-static:register
運(yùn)行arm容器
docker run -it -v /usr/bin/qemu-aarch64-static:/usr/bin/qemu-aarch64-static centosarm架構(gòu)鏡像id
啟動(dòng)成功后自動(dòng)進(jìn)入容器內(nèi)
arm架構(gòu)容器內(nèi)安裝軟件
首先配置國(guó)內(nèi)yum源
cp /etc/yum.repo.d{,.bak} # 備份原有yum源文件
rm -rf /etc/yum.repo.d/* # 清空原有yum源文件
cd /etc/yum.repo.d
vim CentOS-Base.repo
添加如下內(nèi)容,注意是阿里源,同時(shí)設(shè)置gpgcheck=0
,默認(rèn)是1,但是會(huì)報(bào)錯(cuò),報(bào)錯(cuò)內(nèi)容大概如下:
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
驗(yàn)證避免該問(wèn)題的出現(xiàn),無(wú)論如何變更gpgkey地址,都是總會(huì)報(bào)錯(cuò),因此直接設(shè)置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
設(shè)置之后使用yum下載軟件后打包鏡像即可
打包容器為鏡像
docker commit container_id centos-arm:7.9
更多docker commit命令參考 https://www.runoob.com/docker/docker-commit-command.html
x86架構(gòu)上構(gòu)建arm64架構(gòu)的docker鏡像文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-502590.html
about
歡迎關(guān)注我的博客文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-502590.html
到了這里,關(guān)于x86架構(gòu)上構(gòu)建arm64架構(gòu)的docker鏡像的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!