Reputation: 1556
I have problem with understanding the difference between docker build
vs docker buildx build
commands in context of building multi arch images.
In docker documentation I see that docker build
is alias for docker buildx build
:
https://docs.docker.com/reference/cli/docker/buildx/build/
So I assume there should be no differences between them.
I am on M1 Macbook and want to build multi arch image and push it to registry. So I've created new builder with docker-container
driver:
docker buildx create \
--name multi-platform-builder \
--driver docker-container \
--use
With docker buildx ls
I can see that new builder is the default one:
% docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
multi-platform-builder* docker-container
\_ multi-platform-builder0 \_ unix:///var/run/docker.sock running v0.15.2 linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
default docker
\_ default \_ default running v0.13.2 linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
desktop-linux docker
\_ desktop-linux \_ desktop-linux running v0.13.2 linux/arm64, linux/amd64, linux/amd64/v2, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6
Now the questions.
docker build
is an alias for docker buildx build
, why this command does not work:docker build \
--platform=linux/arm64,linux/amd64 \
-t myrepo/myapp:1.0.0 \
-t myrepo/myapp:latest \
--push \
.
and fail with message ERROR: Multi-platform build is not supported for the docker driver.
but buildx build
version works ok:
docker buildx build \
--platform=linux/arm64,linux/amd64 \
-t myrepo/myapp:1.0.0 \
-t myrepo/myapp:latest \
--push \
.
My Docker Desktop version is 4.30.0 with Docker Engine 26.1.1
Upvotes: 9
Views: 8635
Reputation: 705
You are correct that docker build
is an alias of docker buildx build
. However docker build
uses the default
buildx builder which has docker
set a driver and docker
driver doesn't support features like Multi-arch images.
To use custom builder with docker build
command add a --builder
option with the name of your custom builder. So in your case command would look like this.
docker build \
--platform=linux/arm64,linux/amd64 \
-t myrepo/myapp:1.0.0 \
-t myrepo/myapp:latest \
--push \
--builder multi-platform-builder \
.
Upvotes: 11