使用 docker manifest 构建跨平台镜像

本文涉及的产品
容器镜像服务 ACR,镜像仓库100个 不限时长
简介: 使用 docker manifest 构建跨平台镜像

在当今的软件开发领域中,构建跨平台应用程序已经成为了一个普遍存在的需求。不同的操作系统、硬件架构需要不同的镜像环境来支持它们。Docker 作为一个广泛应用的容器化技术,必然需要能够支持构建跨平台镜像,本文将介绍如何使用 docker manifest 来实现构建跨平台镜像。

简介

docker manifest 是 Docker 的一个命令,它提供了一种方便的方式来管理不同操作系统和硬件架构的 Docker 镜像。通过 docker manifest,用户可以创建一个虚拟的 Docker 镜像,其中包含了多个实际的 Docker 镜像,每个实际的 Docker 镜像对应一个不同的操作系统和硬件架构。

docker manifest 命令本身并不执行任何操作。为了操作一个 manifestmanifest list,必须使用其中一个子命令。

manifest 可以理解为是一个 JSON 文件,单个 manifest 包含有关镜像的信息,例如层(layers)、大小(size)和摘要(digest)等。

manifest list 是通过指定一个或多个(理想情况下是多个)镜像名称创建的镜像列表(即上面所说的虚拟 Docker 镜像)。可以像普通镜像一样使用 docker pulldocker run 等命令来操作它。manifest list 通常被称为「多架构镜像」。

注意:docker manifest 命令是实验性的,还未转正。旨在用于测试和反馈,因此其功能和用法可能会在不同版本之间发生变化。

准备工作

工欲善其事,必先利其器,如果想使用 docker manifest 构建多架构镜像,需要具备以下条件。

  • 机器上安装了 Docker。
  • 需要注册一个 Docker Hub 账号。
  • 最少有两个不同平台的主机,用来验证 docker manifest 锁构建出来的多架构镜像正确性(可选)。
  • 联网,docker manifest 命令是需要联网使用的。

为不同平台构建镜像

本文中演示程序所使用的环境是 Apple M2 芯片平台。本地的 Docker 版本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ docker version
Client:
 Cloud integration: v1.0.29
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:01:18 2022
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true
Server: Docker Desktop 4.15.0 (93002)
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 17:59:41 2022
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.10
  GitCommit:        770bd0108c32f3fb5c73ae1264f7e503fe7b2661
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

准备 Dockerfile

首先准备如下 Dockerfile 文件,用来构建镜像。

1
2
3
4
5
FROM alpine
RUN uname -a > /os.txt
CMD cat /os.txt

这个镜像非常简单,构建时将 uname -a 命令输出信息(即当前操作系统的相关信息)写入 /os.txt,运行时将 /os.txt 内容输出。

构建 arm64 平台镜像

因为本机为 Apple M2 芯片,所以使用 docker build 命令构建镜像默认为 arm64 平台镜像。构建命令如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ docker build -t jianghushinian/echo-platform-arm64 .
[+] Building 15.6s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                             0.0s
 => => transferring dockerfile: 94B                                                              0.0s
 => [internal] load .dockerignore                                                                0.0s
 => => transferring context: 2B                                                                  0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                15.5s
 => [1/2] FROM docker.io/library/alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc01  0.0s
 => CACHED [2/2] RUN uname -a > /os.txt                                                          0.0s
 => exporting to image                                                                           0.0s
 => => exporting layers                                                                          0.0s
 => => writing image sha256:f017783a39920aa4646f87d7e5a2d67ab51aab479147d60e5372f8749c3742bb     0.0s
 => => naming to docker.io/jianghushinian/echo-platform-arm64                                    0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

注意:jianghushinian 是我的 Docker Hub 用户名,你在构建镜像时应该使用自己的 Docker Hub 用户名。

如果得到如上类似输出,表明构建成功。

使用 docker run 运行容器进行测试:

1
2
$ docker run --rm jianghushinian/echo-platform-arm64
Linux buildkitsandbox 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 aarch64 Linux

输出内容中的 aarch64 就表示 ARMv8 架构。

现在我们需要将镜像推送到 Docker Hub,确保在命令行中已经使用 docker login 登录过 Docker Hub 的情况下,使用 docker push 命令推送镜像:

1
2
3
4
5
6
$ docker push jianghushinian/echo-platform-arm64
Using default tag: latest
The push refers to repository [docker.io/jianghushinian/echo-platform-arm64]
dd0468cb6cb1: Pushed
07d3c46c9599: Mounted from jianghushinian/demo-arm64
latest: digest: sha256:8eb172234961bf54a01e83d510697f09646c43c297a24f839be846414dfaf583 size: 735

浏览器中登录 Docker Hub 查看推送成功的镜像:

echo-platform-arm64

构建 amd64 平台镜像

无需切换设备,在 Apple M2 芯片的机器上我们可以直接构建 amd64 也就是 Linux 平台镜像,docker build 命令提供了 --platform 参数可以构建跨平台镜像。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ docker build --platform=linux/amd64 -t jianghushinian/echo-platform-amd64 .
[+] Building 15.7s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                      0.0s
 => => transferring dockerfile: 36B                                                                                                                                       0.0s
 => [internal] load .dockerignore                                                                                                                                         0.0s
 => => transferring context: 2B                                                                                                                                           0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                         15.3s
 => CACHED [1/2] FROM docker.io/library/alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300                                                    0.0s
 => [2/2] RUN uname -a > /os.txt                                                                                                                                          0.2s
 => exporting to image                                                                                                                                                    0.0s
 => => exporting layers                                                                                                                                                   0.0s
 => => writing image sha256:5c48af5176402727627cc18136d78f87f0793ccf61e3e3fb4df98391a69e9f70                                                                              0.0s
 => => naming to docker.io/jianghushinian/echo-platform-amd64                                                                                                             0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

镜像构建成功后,同样使用 docker push 命令推送镜像到 Docker Hub:

1
2
3
4
5
6
$ docker push jianghushinian/echo-platform-amd64
Using default tag: latest
The push refers to repository [docker.io/jianghushinian/echo-platform-amd64]
9499dee27c9f: Pushed
8d3ac3489996: Mounted from jianghushinian/demo-amd64
latest: digest: sha256:13cbf21fc8078fb54444992faae9aafca0706a842dfb0ab4f3447a6f14fb1359 size: 735

浏览器中登录 Docker Hub 查看推送成功的镜像:

echo-platform-amd64

你也许会好奇,在 Apple M2 芯片的主机设备上运行 amd64 平台镜像会怎样。目前咱们构建的这个简单镜像其实是能够运行的,只不过会得到一条警告信息:

1
2
3
$ docker run --rm jianghushinian/echo-platform-amd64
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Linux buildkitsandbox 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 x86_64 Linux

输出内容中的 x86_64 就表示 AMD64 架构。

注意:虽然这个简单的镜像能够运行成功,但如果容器内部程序不支持跨平台,amd64 平台镜像无法在 arm64 平台运行成功。

同样的,如果我们登录到一台 amd64 架构的设备上运行 arm64 平台镜像,也会得到一条警告信息:

1
2
3
# docker run --rm jianghushinian/echo-platform-arm64
WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
Linux buildkitsandbox 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 aarch64 Linux

amd64 架构的设备上运行 amd64 平台镜像则不会遇到警告问题:

1
2
# docker run --rm jianghushinian/echo-platform-amd64
Linux buildkitsandbox 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 x86_64 Linux

使用 manifest 合并多平台镜像

我们可以使用 docker manifest 的子命令 create 创建一个 manifest list,即将多个平台的镜像合并为一个镜像。

create 命令用法很简单,后面跟的第一个参数 jianghushinian/echo-platform 即为合并后的镜像,从第二个参数开始可以指定一个或多个不同平台的镜像。

1
2
$ docker manifest create jianghushinian/echo-platform jianghushinian/echo-platform-arm64 jianghushinian/echo-platform-amd64
Created manifest list docker.io/jianghushinian/echo-platform:latest

如上输出,表明多架构镜像构建成功。

注意:在使用 docker manifest create 命令时,确保待合并镜像都已经被推送到 Docker Hub 镜像仓库,不然报错 no such manifest。这也是为什么前文在构建镜像时,都会将镜像推送到 Docker Hub。

此时在 Apple M2 芯片设备上使用 docker run 启动构建好的跨平台镜像 jianghushinian/echo-platform

1
2
$ docker run --rm jianghushinian/echo-platform
Linux buildkitsandbox 5.4.0-80-generic #90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021 aarch64 Linux

没有任何问题,就像在启动 jianghushinian/echo-platform-arm64 镜像一样。

现在我们可以将这个跨平台镜像推送到 Docker Hub,不过,这回我们需要使用的命令不再是 docker push 而是 manifest 的子命令 docker manifest push

1
2
3
4
$ docker manifest push jianghushinian/echo-platform
Pushed ref docker.io/jianghushinian/echo-platform@sha256:13cbf21fc8078fb54444992faae9aafca0706a842dfb0ab4f3447a6f14fb1359 with digest: sha256:13cbf21fc8078fb54444992faae9aafca0706a842dfb0ab4f3447a6f14fb1359
Pushed ref docker.io/jianghushinian/echo-platform@sha256:8eb172234961bf54a01e83d510697f09646c43c297a24f839be846414dfaf583 with digest: sha256:8eb172234961bf54a01e83d510697f09646c43c297a24f839be846414dfaf583
sha256:87b51c1835f13bb722bbb4279fcf50a6da0ecb852433a8f1c04e2f5fe93ac055

浏览器中登录 Docker Hub 查看推送成功的镜像:

echo-platform

进入镜像信息详情页面的 Tags 标签,能够看到镜像支持 amd64arm64/v8 这两个平台。

multi-arch

现在,我们可以在 amd64 架构的设备上同样使用 docker run 命令启动构建好的跨平台镜像 jianghushinian/echo-platform

1
2
# docker run --rm jianghushinian/echo-platform
Linux buildkitsandbox 5.4.0-80-generic #90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021 x86_64 Linux

输出结果没有任何问题。可以发现,无论是 arm64 设备还是 amd64 设备,虽然同样使用 docker run --rm jianghushinian/echo-platform 命令启动镜像,但它们的输出结果都表明启动的是当前平台的镜像,没有再次出现警告。

manifest 功能清单

docker manifest 不止有 create 一个子命令,可以通过 --help/-h 参数查看使用帮助:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ docker manifest --help
Usage:  docker manifest COMMAND
The **docker manifest** command has subcommands for managing image manifests and
manifest lists. A manifest list allows you to use one name to refer to the same image
built for multiple architectures.
To see helpfor a subcommand, use:
    docker manifest CMD --help
For full details on using docker manifest lists, see the registry v2 specification.
EXPERIMENTAL:
  docker manifest is an experimental feature.
  Experimental features provide early access to product functionality. These
  features may change between releases without warning, or can be removed from a
  future release. Learn more about experimental features in our documentation:
https://docs.docker.com/go/experimental/
Commands:
  annotate    Add additional information to a local image manifest
  create      Create a local manifest list for annotating and pushing to a registry
  inspect     Display an image manifest, or manifest list
  push        Push a manifest list to a repository
  rm          Delete one or more manifest lists from local storage
Run 'docker manifest COMMAND --help'for more information on a command.

可以发现,docker manifest 共提供了 annotatecreateinspectpushrm 这 5 个子命。

接下来我们分别看下这几个子命令的功能。

create

先从最熟悉的 create 子命令看起,来看下它都支持哪些功能。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ docker manifest create -h
Flag shorthand -h has been deprecated, please use --help
Usage:  docker manifest create MANIFEST_LIST MANIFEST [MANIFEST...]
Create a local manifest list for annotating and pushing to a registry
EXPERIMENTAL:
  docker manifest create is an experimental feature.
  Experimental features provide early access to product functionality. These
  features may change between releases without warning, or can be removed from a
  future release. Learn more about experimental features in our documentation:
https://docs.docker.com/go/experimental/
Options:
  -a, --amend      Amend an existing manifest list
      --insecure   Allow communication with an insecure registry

笔记:可以看到输出结果第一行的提示,短标志 -h 已经被弃用,推荐使用 --help 查看子命令帮助信息。

可以发现,create 子命令支持两个可选参数 -a/--amend 用来修订已存在的多架构镜像。

指定 --insecure 参数则允许使用不安全的(非 https)镜像仓库。

push

push 子命令我们也见过了,使用 push 可以将多架构镜像推送到镜像仓库。

来看下 push 还支持设置哪些可选参数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ docker manifest push -h
Flag shorthand -h has been deprecated, please use --help
Usage:  docker manifest push [OPTIONS] MANIFEST_LIST
Push a manifest list to a repository
EXPERIMENTAL:
  docker manifest push is an experimental feature.
  Experimental features provide early access to product functionality. These
  features may change between releases without warning, or can be removed from a
  future release. Learn more about experimental features in our documentation:
https://docs.docker.com/go/experimental/
Options:
      --insecure   Allow push to an insecure registry
  -p, --purge      Remove the local manifest list after push

同样的,push 也有一个 --insecure 参数允许使用不安全的(非 https)镜像仓库。

-p/--purge 选项的作用是推送本地镜像到远程仓库后,删除本地 manifest list

inspect

inspect 用来查看 manifest/manifest list 所包含的镜像信息。

其使用帮助如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ docker manifest inspect -h
Flag shorthand -h has been deprecated, please use --help
Usage:  docker manifest inspect [OPTIONS] [MANIFEST_LIST] MANIFEST
Display an image manifest, or manifest list
EXPERIMENTAL:
  docker manifest inspect is an experimental feature.
  Experimental features provide early access to product functionality. These
  features may change between releases without warning, or can be removed from a
  future release. Learn more about experimental features in our documentation:
https://docs.docker.com/go/experimental/
Options:
      --insecure   Allow communication with an insecure registry
  -v, --verbose    Output additional info including layers and platform

--insecure 参数允许使用不安全的(非 https)镜像仓库。这已经是我们第三次看见这个参数了,这也验证了 docker manifest 命令需要联网才能使用的说法,因为这些子命令基本都涉及到和远程镜像仓库的交互。

指定 -v/--verbose 参数可以输出更多信息,包括镜像的 layersplatform 信息。

使用示例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ docker manifest inspect jianghushinian/echo-platform
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [
      {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 735,
"digest": "sha256:13cbf21fc8078fb54444992faae9aafca0706a842dfb0ab4f3447a6f14fb1359",
"platform": {
"architecture": "amd64",
"os": "linux"
         }
      },
      {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 735,
"digest": "sha256:8eb172234961bf54a01e83d510697f09646c43c297a24f839be846414dfaf583",
"platform": {
"architecture": "arm64",
"os": "linux",
"variant": "v8"
         }
      }
   ]
}

从输出信息中可以发现,我们构建的多架构镜像 jianghushinian/echo-platform 包含两个 manifest,可以支持 amd64/arm64 架构,并且都为 linux 系统下的镜像。

指定 -v 参数输出更详细信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$ docker manifest inspect -v jianghushinian/echo-platform
[
	{
"Ref": "docker.io/jianghushinian/echo-platform:latest@sha256:13cbf21fc8078fb54444992faae9aafca0706a842dfb0ab4f3447a6f14fb1359",
"Descriptor": {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"digest": "sha256:13cbf21fc8078fb54444992faae9aafca0706a842dfb0ab4f3447a6f14fb1359",
"size": 735,
"platform": {
"architecture": "amd64",
"os": "linux"
			}
		},
"SchemaV2Manifest": {
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 1012,
"digest": "sha256:5c48af5176402727627cc18136d78f87f0793ccf61e3e3fb4df98391a69e9f70"
			},
"layers": [
				{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 2818413,
"digest": "sha256:59bf1c3509f33515622619af21ed55bbe26d24913cedbca106468a5fb37a50c3"
				},
				{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 211,
"digest": "sha256:1e5897976ad1d3969268a18f4f0356a05875baf0225e39768a9066f43e950ebd"
				}
			]
		}
	},
	{
"Ref": "docker.io/jianghushinian/echo-platform:latest@sha256:8eb172234961bf54a01e83d510697f09646c43c297a24f839be846414dfaf583",
"Descriptor": {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"digest": "sha256:8eb172234961bf54a01e83d510697f09646c43c297a24f839be846414dfaf583",
"size": 735,
"platform": {
"architecture": "arm64",
"os": "linux",
"variant": "v8"
			}
		},
"SchemaV2Manifest": {
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 1027,
"digest": "sha256:f017783a39920aa4646f87d7e5a2d67ab51aab479147d60e5372f8749c3742bb"
			},
"layers": [
				{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 2715434,
"digest": "sha256:9b3977197b4f2147bdd31e1271f811319dcd5c2fc595f14e81f5351ab6275b99"
				},
				{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"size": 212,
"digest": "sha256:edf2b8e1db64e4f46a2190a3dfcb74ae131ae13ad43fcfedde4c3f304c451f7d"
				}
			]
		}
	}
]

annotate

annotate 子命令可以给一个本地镜像 manifest 添加附加的信息。这有点像 K8s Annotations 的意思。

其使用帮助如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ docker manifest annotate -h
Flag shorthand -h has been deprecated, please use --help
Usage:  docker manifest annotate [OPTIONS] MANIFEST_LIST MANIFEST
Add additional information to a local image manifest
EXPERIMENTAL:
  docker manifest annotate is an experimental feature.
  Experimental features provide early access to product functionality. These
  features may change between releases without warning, or can be removed from a
  future release. Learn more about experimental features in our documentation:
https://docs.docker.com/go/experimental/
Options:
      --arch string           Set architecture
      --os string             Set operating system
      --os-features strings   Set operating system feature
      --os-version string     Set operating system version
      --variant string        Set architecture variant

可选参数列表如下:

选项 描述
–arch 设置 CPU 架构信息。
–os 设置操作系统信息。
–os-features 设置操作系统功能信息。
–os-version 设置操作系统版本信息。
–variant 设置 CPU 架构的 variant 信息(翻译过来是“变种”的意思),如 ARM 架构的 v7、v8 等。

例如设置操作系统版本信息,可以使用如下命令:

1
$ docker manifest annotate --os-version macOS jianghushinian/echo-platform jianghushinian/echo-platform-arm64

现在使用 inspect 查看镜像信息已经发生变化:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [
      {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 735,
"digest": "sha256:13cbf21fc8078fb54444992faae9aafca0706a842dfb0ab4f3447a6f14fb1359",
"platform": {
"architecture": "amd64",
"os": "linux"
         }
      },
      {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 735,
"digest": "sha256:8eb172234961bf54a01e83d510697f09646c43c297a24f839be846414dfaf583",
"platform": {
"architecture": "arm64",
"os": "linux",
"os.version": "macOS",
"variant": "v8"
         }
      }
   ]
}

rm

最后要介绍的子命令是 rm,使用 rm 可以删除本地一个或多个多架构镜像(manifest lists)。

1
2
3
4
5
6
7
8
9
10
11
12
13
$ docker manifest rm -h
Flag shorthand -h has been deprecated, please use --help
Usage:  docker manifest rm MANIFEST_LIST [MANIFEST_LIST...]
Delete one or more manifest lists from local storage
EXPERIMENTAL:
  docker manifest rm is an experimental feature.
  Experimental features provide early access to product functionality. These
  features may change between releases without warning, or can be removed from a
  future release. Learn more about experimental features in our documentation:
https://docs.docker.com/go/experimental/

使用示例如下:

1
$ docker manifest rm jianghushinian/echo-platform

现在使用 inspect 查看镜像信息已经不在有 os.version 信息了,因为本地镜像 manifest lists 信息已经被删除,重新从远程镜像仓库拉下来的多架构镜像信息并不包含 os.version

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ docker manifest inspect jianghushinian/echo-platform
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [
      {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 735,
"digest": "sha256:13cbf21fc8078fb54444992faae9aafca0706a842dfb0ab4f3447a6f14fb1359",
"platform": {
"architecture": "amd64",
"os": "linux"
         }
      },
      {
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 735,
"digest": "sha256:8eb172234961bf54a01e83d510697f09646c43c297a24f839be846414dfaf583",
"platform": {
"architecture": "arm64",
"os": "linux",
"variant": "v8"
         }
      }
   ]
}

总结

本文主要介绍了如何使用 docker manifest 来实现构建跨平台镜像。

首先对 docker manifest 进行了简单介绍,它是 Docker 的一个子命令,本身并不执行任何操作,为了操作一个 manifestmanifest list,必须使用它包含的子命令。

接着我们又在 Apple M2 芯片设备上构建了不同平台的镜像,然后使用 manifest list 的能力将其合并成跨平台镜像。

最后对 docker manifest 支持的所有子命令都进行了讲解。

参考

docker manifest 官方文档:https://docs.docker.com/engine/reference/commandline/manifest/

相关实践学习
通过容器镜像仓库与容器服务快速部署spring-hello应用
本教程主要讲述如何将本地Java代码程序上传并在云端以容器化的构建、传输和运行。
深入解析Docker容器化技术
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。     相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
18天前
|
应用服务中间件 Linux nginx
Docker镜像-手动制作yum版nginx镜像
这篇文章介绍了如何手动制作一个基于CentOS 7.6的Docker镜像,其中包括下载指定版本的CentOS镜像,创建容器,配置阿里云软件源,安装并配置nginx,自定义nginx日志格式和web页面,最后提交镜像并基于该镜像启动新容器的详细步骤。
79 21
Docker镜像-手动制作yum版nginx镜像
|
18天前
|
应用服务中间件 nginx Docker
Docker镜像-基于DockerFile制作编译版nginx镜像
这篇文章介绍了如何基于Dockerfile制作一个编译版的nginx镜像,并提供了详细的步骤和命令。
94 17
Docker镜像-基于DockerFile制作编译版nginx镜像
|
2天前
|
负载均衡 网络协议 开发者
掌握 Docker 网络:构建复杂的容器通信
在 Docker 容器化环境中,容器间的通信至关重要。本文详细介绍了 Docker 网络的基本概念和类型,包括桥接网络、宿主网络、覆盖网络和 Macvlan 网络等,并提供了创建、管理和配置自定义网络的实用命令。通过掌握这些知识,开发者可以构建更健壮和灵活的容器化应用,提高应用的可扩展性和安全性。
|
18天前
|
应用服务中间件 Linux nginx
Docker镜像管理篇
关于Docker镜像管理的教程,涵盖了Docker镜像的基本概念、管理命令以及如何制作Docker镜像等内容。
89 7
Docker镜像管理篇
|
18天前
|
应用服务中间件 Linux nginx
Docker镜像-基于DockerFile制作yum版nginx镜像
本文介绍了如何使用Dockerfile制作一个基于CentOS 7.6.1810的yum版nginx镜像,并提供了详细的步骤和命令。
60 20
|
6天前
|
Devops jenkins 持续交付
DevOps实践:构建和部署一个Docker化的应用
【9月更文挑战第14天】在当今快节奏的软件开发领域,DevOps已经成为提升效率、加速交付的关键。本文将引导你理解DevOps的核心概念,并通过一个实际的示例—构建和部署一个Docker化的应用—来深入探讨其实践方法。我们将从简单的应用出发,逐步实现Docker容器化,并最终通过CI/CD流水线自动化部署过程。这不仅是对DevOps流程的一次实操演练,也是对现代软件开发理念的一次深刻体验。
|
8天前
|
Kubernetes Docker 微服务
构建高效的微服务架构:基于Docker和Kubernetes的最佳实践
在现代软件开发中,微服务架构因其灵活性和可扩展性而受到广泛青睐。本文探讨了如何利用Docker和Kubernetes来构建高效的微服务架构。我们将深入分析Docker容器的优势、Kubernetes的编排能力,以及它们如何结合实现高可用性、自动扩展和持续部署。通过具体的最佳实践和实际案例,读者将能够理解如何优化微服务的管理和部署过程,从而提高开发效率和系统稳定性。
|
18天前
|
Docker 容器
Docker Hub镜像公共仓库使用
这篇文章介绍了如何使用Docker Hub公共仓库进行镜像的创建、上传、下载和管理。
308 8
|
24天前
|
存储 安全 Ubuntu
Docker 镜像与 Docker 容器的区别
【8月更文挑战第27天】
64 5
|
24天前
|
运维 Ubuntu Shell
掌握Docker容器的创建:从镜像到实例
【8月更文挑战第27天】
93 4