How Docker selects an image's os/arch
Solution 1:
I'm wondering what image I'll get if I just do a "docker pull python"
From "Leverage multi-CPU architecture support"
Most of the Docker Official Images on Docker Hub provide a variety of architectures.
For example, thebusybox
image supportsamd64
,arm32v5
,arm32v6
,arm32v7
,arm64v8
,i386
,ppc64le
, ands390x
.
When running this image on anx86_64
/amd64
machine, theamd64
variant is pulled and run.
So it depends on the OS used when you do your docker pull
.
and how I can choose the OS and architecture myself.
The same page adds:
You can also run images targeted for a different architecture on Docker Desktop.
You can run the images using the SHA tag, and verify the architecture.
For example, when you run the following on a macOS:docker run --rm docker.io/username/demo:latest@sha256:2b77acdfea5dc5baa489ffab2a0b4a387666d1d526490e31845eb64e3e73ed20 uname -m
aarch64
docker run --rm docker.io/username/demo:latest@sha256:723c22f366ae44e419d12706453a544ae92711ae52f510e226f6467d8228d191 uname -m
armv71
In the above example, uname -m returns aarch64 and armv7l as expected, even when running the commands on a native macOS or Windows developer machine
Solution 2:
It's based on the host platform where docker is running. You can see this in docker info
:
$ docker info --format '{{ .OSType }}/{{ .Architecture }}'
linux/x86_64
The code for this is in containerd and the OS and Arch are looked up slightly differently in go:
$ go env
GO111MODULE=""
GOARCH="amd64"
...
GOOS="linux"
...