What is the difference between below two docker commands?

huangapple go评论84阅读模式
英文:

What is the difference between below two docker commands?

问题

我正在使用MacBook M1来构建Go项目的Docker镜像,该项目依赖于confluent-kafka-go库,因此必须使用以下两种方式之一。

两种方式都可以工作,但它们有什么区别呢?
从我所看到的,第一种方式使用了多平台镜像,而第二种方式使用了特殊的amd64/golang镜像。

docker run --platform linux/amd64 --rm -v $PWD:/build -w /build -e GOOS=linux -e GOARCH=amd64 golang:1.17-buster go build
docker run --rm -v "$PWD":/build -w /build -e GOOS=linux -e GOARCH=amd64 amd64/golang:1.17 go build
英文:

I'm trying use MacBook M1 with docker build Go project, this project depends on lib confluent-kafka-go, thus must use below ways.

Both works, but what's the difference?
What I can see, first one use multi-platform image, second one use a special amd64/golang image.

docker run --platform linux/amd64 --rm -v $PWD:/build -w /build -e GOOS=linux -e GOARCH=amd64 golang:1.17-buster go build
docker run --rm -v "$PWD":/build -w /build -e GOOS=linux -e GOARCH=amd64 amd64/golang:1.17 go build

答案1

得分: 2

这是“共享标签”和“简单标签”之间的区别:

  • “简单标签”是一个“单一”Linux或Windows镜像的实例。
    通常是一个清单列表,可以包含为其他架构构建的相同镜像;例如,mongo:4.0-xenial目前有针对amd64和arm64v8的镜像。
    Docker守护程序负责选择适合主机架构的镜像。

  • “共享标签”是始终指向清单列表的标签,该列表包括所有各自镜像架构的多个版本的Windows和Linux镜像的组合 - 在mongo示例中,4.0标签是一个共享标签,包含(在撰写本文时)所有的4.0-xenial、4.0-windowsservercore-ltsc2016、4.0-windowsservercore-1709和4.0-windowsservercore-1803。

因此:

  • “简单标签”使得docker run mongo:4.0-xenial在单个平台上(在mongo:4.0-xenial的情况下是Linux)上“做正确的事情”。
  • “共享标签”使得docker run mongo:4.0在Linux和支持的各个Windows版本上大致工作(例如Windows Server Core LTSC 2016),其中Docker守护程序再次负责根据主机平台和版本确定适当的镜像。

在你的情况下,Docker Golang镜像提供了两个标签:

  • golang:1.17-buster是一个共享标签,通过--platform选项提取了linux/amd64
    如果你没有指定平台,会得到一个警告,如下所示:

    The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm/v7) and no specific platform was requested

  • amd64/golang:1.17是一个简单标签,已经适用于linux/amd64

英文:

That would be the difference between ""Shared" and "Simple" tags":

> - "Simple Tags" are instances of a "single" Linux or Windows image.
It is often a manifest list that can include the same image built for other architectures; for example, mongo:4.0-xenial currently has images for amd64 and arm64v8.
The Docker daemon is responsible for picking the appropriate image for the host architecture.
>
> - "Shared Tags" are tags that always point to a manifest list which includes some combination of potentially multiple versions of Windows and Linux images across all their respective images' architectures -- in the mongo example, the 4.0 tag is a shared tag consisting of (at the time of this writing) all of 4.0-xenial, 4.0-windowsservercore-ltsc2016, 4.0-windowsservercore-1709, and 4.0-windowsservercore-1803.

So:

> - The "Simple Tags" enable docker run mongo:4.0-xenial to "do the right thing" across architectures on a single platform (Linux in the case of mongo:4.0-xenial).
> - The "Shared Tags" enable docker run mongo:4.0 to roughly work on both Linux and as many of the various versions of Windows that are supported (such as Windows Server Core LTSC 2016, where the Docker daemon is again responsible for determining the appropriate image based on the host platform and version).

In your case, the Docker Golang image offers both tags

  • golang:1.17-buster is a shared tag, from which you are extracting the linux/amd64 through the --platform option.
    If you did not specify the platform, would get a warning like:

    The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm/v7) and no specific platform was requested

  • amd64/golang:1.17 is a simple tag, already tailored to linux/amd64

huangapple
  • 本文由 发表于 2022年10月10日 13:42:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/74010617.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定