简体   繁体   English

Docker 如何选择图像的操作系统/架构

[英]How Docker selects an image's os/arch

I started to learn how to work with Docker and I had this question.我开始学习如何使用 Docker 并且我有这个问题。 When I make "docker pull <image-name>" I usually pull the image from docker hub.当我制作“docker pull <image-name>”时,我通常从 docker 集线器中提取图像。

But images can have different versions that differ in OS and architecture.但是图像可以有不同的版本,在操作系统和架构上有所不同。 For example a python image has versions with linux and windows.例如,python 映像的版本具有 linux 和 windows。

蟒蛇图像标签

I'm wondering what image I'll get if I just do a "docker pull python" and how I can choose the OS and architecture myself.我想知道如果我只做一个“docker pull python”我会得到什么图像,以及我如何自己选择操作系统和架构。

I actually prefer to use linux images because it's lightweight and I don't want accidentally pull a windows image.我实际上更喜欢使用 linux 图像,因为它是轻量级的,我不想意外拉出 windows 图像。

It's based on the host platform where docker is running.它基于运行 docker 的主机平台。 You can see this in docker info :您可以在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:此代码在containerd 中,在 go 中查找 OS 和 Arch 略有不同:

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

I'm wondering what image I'll get if I just do a "docker pull python"我想知道如果我只做一个“docker pull python”我会得到什么图像

From " Leverage multi-CPU architecture support "来自“利用多 CPU 架构支持

Most of the Docker Official Images on Docker Hub provide a variety of architectures. Docker Hub上的Docker官方图片大部分都提供了多种架构。
For example, the busybox image supports amd64 , arm32v5 , arm32v6 , arm32v7 , arm64v8 , i386 , ppc64le , and s390x .例如, busybox映像支持amd64arm32v5arm32v6arm32v7arm64v8i386ppc64les390x
When running this image on an x86_64 / amd64 machine, the amd64 variant is pulled and run.x86_64 / amd64机器上运行此映像时,会拉取并运行amd64变体。

So it depends on the OS used when you do your docker pull .因此,这取决于您执行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.您还可以在 Docker Desktop 上运行针对不同架构的映像。

You can run the images using the SHA tag, and verify the architecture.您可以使用 SHA 标记运行映像,并验证架构。
For example, when you run the following on a macOS:例如,当您在 macOS 上运行以下命令时:

 docker run --rm docker.io/username/demo:latest@sha256:2b77acdfea5dc5baa489ffab2a0b4a387666d1d526490e31845eb64e3e73ed20 uname -m

aarch64 aarch64

 docker run --rm docker.io/username/demo:latest@sha256:723c22f366ae44e419d12706453a544ae92711ae52f510e226f6467d8228d191 uname -m

armv71 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在上面的示例中,uname -m 按预期返回 aarch64 和 armv7l,即使在本机 macOS 或 Windows 开发人员机器上运行命令时也是如此

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM