Install Docker
Install Docker Registry
Install buildx
-
buildx
默認(rèn)使用的 構(gòu)建器( builder ) 驅(qū)動(dòng)是docker driver
,它不支持同時(shí)構(gòu)建多個(gè) platform 的鏡像
# 查看默認(rèn)構(gòu)建器
docker buildx ls
- 使用
docker buildx create
創(chuàng)建docker-container driver
的構(gòu)建器
BUILDER_NAME=multiArch-cloudNative
# export image to localhost registry
## https://github.com/docker/buildx/issues/94
## https://stackoverflow.com/questions/60430255/using-docker-buildx-failed-to-push-image-to-resgistry-no-such-host
docker buildx create --name multiArch-opt-driver --driver-opt network=host --use
# docker buildx create --name $BUILDER_NAME --use
# docker buildx use $BUILDER_NAME
- 啟動(dòng)容器 buildx_buildkit
# docker buildx自動(dòng)下載 moby/buildkit:buildx-stable-1 鏡像
docker buildx inspect --bootstrap
- Multi-platform build: Docker uses QEMU to emulate other architectures for multi-platform builds. Make sure that QEMU is installed and that Docker is configured to use it.
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- QEMU 仿真支持
docker pull tonistiigi/binfmt
docker run --privileged --rm tonistiigi/binfmt --install all
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
Usage
-
--push
:將構(gòu)建的鏡像推送到鏡像倉庫
同時(shí)進(jìn)行多架構(gòu)編譯
docker buildx build --push --platform linux/amd64,linux/arm64 \
--pull --no-cache \
--build-arg "TAG=$BASE_IMAGE_VERSION" -t localhost:5000/my-image:1.0.0 .
在x86_64環(huán)境編譯aarch64鏡像
image_name=my-image
version=1.0.0
docker buildx build --push --platform linux/arm64 \
--pull --no-cache \
-f Dockerfile.aarch64 \
-t localhost:5000/${image_name}:${version} .
Pull image
pull image時(shí)加上--platform參數(shù)
docker pull localhost:5000/my-image:1.0.0 --platform=linux/arm64
docker pull localhost:5000/my-image:1.0.0 --platform=linux/amd64
FAQ
Install buildx separately
As of Docker Engine 23.0 and Docker Desktop 4.19, Buildx is the default build client.
ARCH=$(uname -m)
[ "${ARCH}" == "x86_64" ] && ARCH=amd64
[ "${ARCH}" == "aarch64" ] && ARCH=arm64
BUILDX_VERSION=v0.10.4
wget https://github.com/docker/buildx/releases/download/${BUILDX_VERSION}/buildx-${BUILDX_VERSION}.linux-${ARCH}
mkdir -pv ~/.docker/cli-plugins
mv buildx-${BUILDX_VERSION}.linux-${ARCH} ~/.docker/cli-plugins/
ls -alh $HOME/.docker/cli-plugins
chmod +x ~/.docker/cli-plugins/docker-buildx
ERROR: multiple platforms feature is currently not supported for docker driver. Please switch to a different driver (eg. "docker buildx create --use")
# 確保默認(rèn)的構(gòu)建器是 buildx
docker buildx ls
docker buildx create --name multiArch-cloudNative
docker buildx use multiArch-cloudNative
docker buildx inspect --bootstrap