docker多平台构建像参考文档:
https://docs.docker.com/build/building/multi-platform/
安装docker
二进制安装docker
https://download.docker.com/linux/static/stable/
https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz
docker 安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| $ wget https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz $ tar zxvf docker-24.0.7.tgz docker/ docker/docker-init docker/containerd-shim-runc-v2 docker/ctr docker/docker-proxy docker/dockerd docker/docker docker/containerd docker/runc $ mv docker/* /usr/bin
$ wget -O /usr/lib/systemd/system/docker.service \ https://raw.githubusercontent.com/docker/packaging/main/pkg/docker-engine/common/systemd/docker.service
$ systemctl daemon-reload $ systemctl enable docker
|
buildx安装
https://github.com/docker/buildx/releases
1 2 3
| $ mkdir -p ~/.docker/cli-plugins $ wget -O ~/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.12.0/buildx-v0.12.0.linux-amd64 $ chmod +x ~/.docker/cli-plugins/docker-buildx
|
yum 安装docker
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
| $ sudo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ sudo yum -y install docker-ce
yum list docker-ce --showduplicates|grep "^doc"|sort -r docker-ce.aarch64 3:24.0.7-1.el7 @docker-ce-stable docker-ce.aarch64 3:24.0.0-1.el7 docker-ce-stable docker-ce.aarch64 3:23.0.6-1.el7 docker-ce-stable docker-ce.aarch64 3:23.0.0-1.el7 docker-ce-stable docker-ce.aarch64 3:20.10.23-3.el7 docker-ce-stable docker-ce.aarch64 3:20.10.0-3.el7 docker-ce-stable docker-ce.aarch64 3:19.03.9-3.el7 docker-ce-stable docker-ce.aarch64 3:19.03.5-3.el7 docker-ce-stable
$ yum -y install docker-ce-24.0.7-1.el7 docker-ce-cli-24.0.7-1.el7 docker-ce-rootless-extras-24.0.7-1.el7
$ sudo mkdir -p /etc/docker $ sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://l0zsxxuv.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
|
多架构构建
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| $ sudo docker run --rm --privileged tonistiigi/binfmt:latest --install all
$ docker buildx create --name mult-arch--busybox --driver docker-container --use mult-arch--busybox
$ docker buildx inspect --bootstrap --builder mult-arch--busybox
$ cat <<EOF > Dockerfile FROM busybox:latest CMD sleep inf EOF $ docker login ghcr.io
$ docker buildx build --platform linux/amd64,linux/arm64 --tag ghcr.io/zmquan/busybox:mult-arch --push .
|