文章目录
  • buildx测试
  • 前提条件
  • 安装
  • 构建镜像
  • 推送http私库问题
  • docker容器里运行docker buildx

在x86架构下如何打包arm64架构的镜像,docker buildx 是docker的一个插件,使用qemu作为底层支撑。

buildx测试

前提条件

组件

版本

docker

v20.10.15

rocky linux (centos 8)

v8.5

安装

参考:Build multi-platform images

安装

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

创建builder

docker buildx create --use --name mybuild default
构建镜像

使用go语言为例子,参考这位大佬博客

cat > hello.go <<EOF
package main

import (
        "fmt"
        "runtime"
)

func main() {
        fmt.Printf("Hello, %s!\n", runtime.GOARCH)
}
EOF

Dockerfile

cat > Dockerfile <<EOF
FROM golang:alpine AS builder
ENV GO111MODULE auto
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN go build -o hello .

FROM alpine
RUN mkdir /app
WORKDIR /app
COPY --from=builder /app/hello .
CMD ["./hello"]
EOF

开始构建镜像

# 本地打包
docker buildx build -t test --platform=linux/arm64 . --load
# 在远程主机打包,需要修改docker.service文件
docker -H tcp://192.168.10.75:2375 buildx build -t test --platform=linux/arm64 . --load