Docker 如何选择图像的 os/arch

How Docker selects an image's os/arch

我开始学习如何使用 Docker,我有这个问题。 当我制作“docker pull ”时,我通常会从 docker hub 拉取图像。

但是图像可以有不同的版本,这些版本在 OS 和体系结构上有所不同。例如,python 图像的版本为 linux 和 windows。

我想知道如果我只是做一个“docker pull python”我会得到什么图像,以及我如何自己选择 OS 和架构。

我实际上更喜欢使用 linux 图片,因为它很轻,我不想不小心拉出 windows 图片。

它基于 docker 为 运行 的主机平台。您可以在 docker info:

中看到
$ docker info --format '{{ .OSType }}/{{ .Architecture }}'
linux/x86_64

此代码在 containerd 中,OS 和 Arch 在 go 中的查找略有不同:

$ go env
GO111MODULE=""
GOARCH="amd64"
...
GOOS="linux"
...

I'm wondering what image I'll get if I just do a "docker pull python"

来自“Leverage multi-CPU architecture support

Most of the Docker Official Images on Docker Hub provide a variety of architectures.
For example, the busybox image supports amd64, arm32v5, arm32v6, arm32v7, arm64v8, i386, ppc64le, and s390x.
When running this image on an x86_64 / amd64 machine, the amd64 variant is pulled and run.

所以这取决于您在执行 docker pull 时使用的 OS。


and how I can choose the OS and architecture myself.

同页添加:

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