• 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

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(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
    
    • 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镜像

    about

    欢迎关注我的博客

  • 相关阅读:
    麒麟系统上使用linuxdeployqt 编译安装
    X86 SMAP(Supervisor Mode Access Prevention)机制引入的一个问题分析
    腾讯云服务器+宝塔+后端+前端发布
    [Spring笔记] Spring-27-Spring整合MyBatis
    Java中的文件操作(基础知识+三个小程序练习)
    2024深圳电子展,推动中国电子产业快速发展,助力中国数字经济实现高质量发展
    jQuery使用的简单总结
    Kubernetes(K8S) kubesphere 介绍
    软考 - 系统架构设计师 - ESB(企业服务总线)例题
    vue项目 element UI input框扫码枪扫描过快 出现数据丢失问题(已解决二)
  • 原文地址:https://blog.csdn.net/HYESC/article/details/126701828