banner
NEWS LETTER

DockerHub上传双架构镜像

Scroll down

本文作者:丁辉

DockerHub上传双架构镜像

Docker manifest 推送双架构镜像

官网文档

  1. 构建并推送镜像

    • X85执行

      1
      2
      docker build -t offends/demo-x86:v1 .
      docker push offends/demo-x86:v1
    • arm执行

      1
      2
      docker build -t offends/demo-arm:v1 .
      docker push offends/demo-arm:v1
  2. 创建 manifest

    1
    2
    3
    docker manifest create offends/demo:v1  \
    offends/demo-x86:v1 \
    offends/demo-arm:v1
  3. 为镜像指定架构

    1
    2
    3
    4
    5
    6
    7
    docker manifest annotate offends/demo-x86:v1 \
    offends/demo-x86:v1 \
    --os linux --arch x86_64

    docker manifest annotate offends/demo-arm:v1 \
    offends/demo-arm:v1 \
    --os linux --arch arm64 --variant v8
  4. 查看

    1
    docker manifest inspect offends/demo:v1
  5. 推送

    1
    docker manifest push offends/demo:v1

Docker Buildx 推送双架构镜像

Buildx二进制文件下载

模拟仓库文档

官网文档

  1. 安装 Buildx

    1
    2
    3
    4
    mkdir -p ~/.docker/cli-plugins
    mv buildx-v*.linux-amd64 ~/.docker/cli-plugins/docker-buildx
    chmod +x ~/.docker/cli-plugins/docker-buildx
    docker buildx version
  2. 添加模拟仓库

    1
    docker run --privileged --rm tonistiigi/binfmt --install all

    内核版本需要升级,如果过低无法添加成功

  3. 查看

    1
    2
    3
    4
    5
    docker buildx ls
    #一下是输出
    NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
    default * docker
    default default running v0.8+unknown linux/amd64, linux/386, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/arm/v7, linux/arm/v6
  4. 创建 builder 示例

    1
    docker buildx create --name dmeo --use
  5. 构建混合建构镜像

    1
    docker buildx build --platform linux/amd64,linux/arm64/v8 -t demo:v1 --push .

Docker Buildx使用私有仓库 推送双架构镜像

部署私有镜像仓库

Docker hub文档

GitHub文档

  1. 启动镜像仓库

    1
    2
    3
    4
    5
    6
    docker run -d \
    --name docker-registry \
    --restart=always \
    -p 5000:5000 \
    -v /root/private-registry:/var/lib/registry \
    registry
  2. 将本机Docker添加非安全仓库

    Buildx 只允许 https 协议的镜像仓库使用,这里的方法之建议测试使用

    1
    2
    3
    4
    5
    6
    cat > /etc/docker/daemon.json <<EOF
    {
    "experimental": true,
    "insecure-registries": ["192.168.1.10:5000"]
    }
    EOF
  3. 重启 docker 进程启用

    1
    systemctl restart docker
  4. 将 buildkit 镜像推送到私仓

    1
    2
    docker tag moby/buildkit:buildx-stable-1 192.168.1.10:5000/buildkit:buildx-stable-1
    docker push 192.168.1.10:5000/buildkit:buildx-stable-1
  5. 新增 buildkit 私仓配置

    1
    2
    3
    4
    5
    6
    cat > /etc/buildkit/buildkitd.toml << EOF
    debug = true
    [registry."192.168.1.10:5000"]
    http = true
    insecure = true
    EOF
  6. 创建 builder

    1
    2
    3
    4
    docker buildx create --use \
    --name builder \
    --driver-opt image=192.168.1.10:5000/buildkit:buildx-stable-1 \
    --config /etc/buildkit/buildkitd.toml
  7. 构建混合建构镜像

    1
    docker buildx build --platform linux/amd64,linux/arm64/v8 -t 192.168.1.10:5000/demo:v1 --push .
  8. 查看

    1
    curl  http://192.168.1.10:5000/v2/_catalog

清理

删除构建器实例

1
docker buildx rm builder

I'm so cute. Please give me money.

其他文章
cover
Docker-fio磁盘读写测试
  • 70/01/01
  • 00:00
  • Kubernetes-Docker
cover
Docker上下文配置
  • 70/01/01
  • 00:00
  • Kubernetes-Docker
目录导航 置顶
  1. 1. DockerHub上传双架构镜像
    1. 1.1. Docker manifest 推送双架构镜像
    2. 1.2. Docker Buildx 推送双架构镜像
    3. 1.3. Docker Buildx使用私有仓库 推送双架构镜像
      1. 1.3.1. 部署私有镜像仓库
      2. 1.3.2. 清理
请输入关键词进行搜索