While building docker images very often we need to deploy it into a different CPU architecture than the one used to build the image.
For example you might be building in a Linux amd64
server but you’ll deploy
into an IoT arm64
CPU (e.g. A RaspberryPi).
For such scenarios docker includes the buildx
command, which takes care
of multi-arch support for us.
Use the buildx
command to create a specific builder that supports multi-arch
image builds
docker buildx create --name <name_your_builder> --use
Some useful buildx commands:
# List all available builders
docker buildx ls
# Switch to a specific builder
docker buildx use hservices
# List all docker contexts
docker context ls
Once you have created and selected your builder, you can use docker buildx build
to create your image.
For this example:
linux/amd64
and linux/arm64
architecturestest.dockerimage
giobyte8/test:1.0.0
# Build and push image to registry
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t giobyte8/test:1.0.0 \
-f scanner.dockerfile \
--push \
..
You can remove the
--push
argument to prevent image from being uploaded to docker registry