Publish: 2022-02-14 | Modify: 2022-02-14
By default, x86_64 platform can only build x86_64 images. If you need to build multi-platform images (such as ARM64) on x86_64 platform, you can use the Buildx tool provided by Docker.
In this article, we take CentOS 7 x64 system as an example. The latest download page for Docker Buildx is: https://github.com/docker/buildx/releases/latest. The latest version at the time of writing this article is v0.7.1
. The installation process is as follows.
# Download Buildx
wget https://github.com/docker/buildx/releases/download/v0.7.1/buildx-v0.7.1.linux-amd64
# Create target folder
mkdir -p $HOME/.docker/cli-plugins
# Move file
mv buildx-v0.7.1.linux-amd64 $HOME/.docker/cli-plugins/docker-buildx
# Add execute permission
chmod +x ~/.docker/cli-plugins/docker-buildx
Docker Buildx is an experimental feature and is not enabled by default. You need to modify /etc/docker/daemon.json
and add a line:
"experimental": true
to enable this feature. Next, perform the initialization:
docker buildx create --name builderx
docker buildx use builderx
docker buildx inspect --bootstrap
After installing and enabling Docker Buildx, we can use it to build multi-platform images. For example, the original build command is:
build -t ${IMAGE_NAME}:${VERSION} .
The build command using Docker Buildx is:
docker buildx build --platform linux/amd64,linux/arm64 -t ${IMAGE_NAME}:${VERSION} . --push
linux/amd64
, linux/arm64
, or darwin/amd64
.After the build is completed, we can find the corresponding tag of the image to see the support for multiple platforms.
If your image supports multiple platforms, when pulling the image, it will automatically download the corresponding platform image based on your platform.
--push
parameter, otherwise the image cannot be seen in docker images
. I'm not sure about the specific reason for this.Some content in this article is referenced from:
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.