Docker: Using amd64 Images on Apple M1
My current home development setup includes an Apple M1 laptop and a Windows 10 desktop with an AMD chip. For projects that require prebuilt libraries, I’ll just use a Docker container. I can either instruct docker to build for both aarch64
and amd64
, or just one image. If the latter option is an Intel-based architecture like amd64
, x86_64
, or x64
, then I would have to cross-build the image on Apple M1 (aarch64
).
Run It
Spin up a container using:
docker run --rm -it --platform=linux/amd64 alpine sh
Replacing alpine
with the image you want to spin up. Ensure you’re in the correct environment using:
uname -a
The output should mention Linux 89a13e8a6753 5.10.25-linuxkit #1 SMP PREEMPT Tue Mar 23 09:24:45 UTC 2021 x86_64 Linux
. If it fails at any point, you likely built or pulled the wrong OS/ARCH combination.
Ensure linux/amd64
First ensure that there is a linux/amd64
variant of the image in question.
You can check if the image has the x86_64
(also known as amd64
) icon within the Docker hub. On other registries, like GitLab, there is no indication unfortunately. Although, the OS/ARCH type is very common so it is likely that it is default. If you are unsure, you can build the image locally using docker build . --platform linux/amd64
.
Ensure the image you’ve pulled/built using docker image inspect alpine
[
{
"Id": "sha256:d4ff818577bc193b309b355b02ebc9220427090057b54a59e73b79bdfe139b83",
"RepoTags": [
"alpine:latest"
],
"RepoDigests": [
"alpine@sha256:234cb88d3020898631af0ccbbcca9a66ae7306ecd30c9720690858c1b007d2a0"
],
"Parent": "",
"Comment": "",
"Created": "2021-06-15T22:19:37.842991933Z",
"Container": "8a1f6c9b61cbbf8d570f0f63099b6649bf6b65e1632bf797727e201801cc21e2",
"ContainerConfig": {
"Hostname": "8a1f6c9b61cb",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/bin/sh\"]"
],
"Image": "sha256:adc3ec15388a285a57a75278249afca8cef6e9542d280f2b9d52cee06ac55899",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "19.03.12",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh"
],
"Image": "sha256:adc3ec15388a285a57a75278249afca8cef6e9542d280f2b9d52cee06ac55899",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 5595013,
"VirtualSize": 5595013,
"GraphDriver": {
"Data": {
"MergedDir": "/var/lib/docker/overlay2/d1fb5ea73e3e5b23e4a0834d2b8340dce683429a6de061086b0684844591900a/merged",
"UpperDir": "/var/lib/docker/overlay2/d1fb5ea73e3e5b23e4a0834d2b8340dce683429a6de061086b0684844591900a/diff",
"WorkDir": "/var/lib/docker/overlay2/d1fb5ea73e3e5b23e4a0834d2b8340dce683429a6de061086b0684844591900a/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:72e830a4dff5f0d5225cdc0a320e85ab1ce06ea5673acfe8d83a7645cbd0e9cf"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
Ensure that it mentions "Architecture": "amd64"
and you’re good to go! Try to spin it up!