Jay Taylor's notes
back to listing indexHow to build x86 (and others!) Docker images on an M1 Mac – Jaimyn's Blog
[web search]Once you’re there, select “Experimental Features” and toggle the slider to on. Click on “Apply & Restart” to save the changes and restart the Docker daemon.
If you can’t see an “Experimental Features” option, you may have to sign up for the Docker developer program at this link < attr(href) > . I suspect it’s a new thing which is why only recently created accounts seem to need to sign up.
Once you’ve enabled experimental features, you can close the Docker Desktop preferences. In your terminal, open the folder that contains the Dockerfile you wish to build for multiple architectures. Run the docker buildx ls
command to list the current builder instances. You should see something similar to below.
$ docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS PLATFORMS
default * docker
default default running linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/arm/v7, linux/arm/v6
Next create a new builder instance with docker buildx create --use
so we can perform multiple builds in parallel. Without this step, you’ll have to use the default Docker one which only supports a single platform per build. You’ll see it created if you run docker buildx ls
again.
$ docker buildx lsNAME/NODE DRIVER/ENDPOINT STATUS PLATFORMS
reverent_banach * docker-container
reverent_banach0 unix:///var/run/docker.sock running linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/arm/v7, linux/arm/v6
default docker
default default running linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/arm/v7, linux/arm/v6
Now you can use buildx
like below to start a multi-architecture build. You’ll have to push it straight to a registry (either the public or a private one) with --push
if you want Docker to automatically manage the multi-architecture manifest for you. Don’t forget to tag it (the example is using the open source MemberMatters < attr(href) > software I wrote) and add a list of all the platforms that you wish to build for. You can see the compatible platforms from the previous docker buildx ls
command. The command below will build an image for both Apple Silicon Macs (linux/arm64
), and standard x86 platforms (linux/amd64
).
$ docker buildx build --platform linux/amd64,linux/arm64 --push -t membermatters/membermatters .
The first time you run a build, you’ll have to wait for the Moby BuildKit image to download so you’ll see something like this.
$ docker buildx build --platform linux/amd64,linux/arm64 --push -t membermatters/membermatters .
[+] Building 16.5s (7/43)
=> [internal] booting buildkit 10.4s
=> => pulling image moby/buildkit:buildx-stable-1 8.1s
=> => creating container buildx_buildkit_admiring_shirley0
Once the build is finished, it will be automatically uploaded to your configured registry. Docker will also automatically manage the manifest < attr(href) > list for you. This allows Docker to combine the separate builds for each architecture into a single “manifest”. This means users can do a normal docker pull <image>
and the Docker client will automatically work out the correct image for their CPU architecture – pretty neat!
TLDR; Version
- Open the Docker Desktop dashboard then open up Preferences (cog icon). Go to “Experimental Features” then turn it on and apply it.
- Next create a new builder instance with
docker buildx create --use
. This lets you specify multiple docker platforms at once. - To build your Dockerfile for typical x86 systems and Apple Silicon Macs, run
docker buildx build --platform linux/amd64,linux/arm64 --push -t <tag_to_push> .
- Done. Please note that you have to push directly to a repository if you want Docker Desktop to automatically manage the manifest list for you (this is probably something you want). Read the paragraph above to find out why.
27 replies on “How to build x86 (and others!) Docker images on an M1 Mac”
[acbp@acmba:~/data/built/acpytest] docker –version
Docker version 20.10.7, build f0df35096d
[acbp@acmba:~/data/built/acpytest] docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS PLATFORMS
default * docker
default default running linux/arm64, linux/amd64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
[acbp@acmba:~/data/built/acpytest] docker buildx build –platform linux/amd64 –push -t my_dockerhub_org/actest:0.0.13-test1
error: “docker buildx build” requires exactly 1 argument.
See ‘docker buildx build –help’.
Usage: docker buildx build [OPTIONS] PATH | URL | –
Start a build
=> [internal] booting buildkit 19.3s
=> => pulling image moby/buildkit:buildx-stable-1 17.2s
=> => creating container buildx_buildkit_sweet_elgamal0 2.1s
=> ERROR [internal] load build definition from Dockerfile 1.0s
=> => transferring dockerfile: 40B 0.1s
=> ERROR [internal] load .dockerignore 1.1s
=> => transferring context: 40B 0.0s
——
> [internal] load build definition from Dockerfile:
——
——
> [internal] load .dockerignore:
——
error: failed to solve: rpc error: code = Unknown desc = failed to read dockerfile: error from sender: open .Trash: operation not permitted
– trying to compile x86 rust application inside docker container
– no arm64 image equivalents in registry
– getting segfault from qemu on compiling anyhow library dependency
– segfault happens on `docker buildx build –platform linux/amd64,linux/arm64 –push –tag some_tag:latest .
– tried running containers with FROM –platform=linux/amd64, results in segfault
Do you guys have a solution for this kind of issue? Any help would be amazing
I am running latest Docker Desktop for Mac 4.5.0 (74594) and enabled experimental features, sorry for double post, adding this just for clarification.
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website