docker manifest

描述管理 Docker 镜像 manifest 和 manifest 列表
用法docker manifest COMMAND

实验性

此命令是实验性的。

实验性功能旨在用于测试和反馈,因为其功能或设计可能会在版本之间发生变化,恕不另行通知,或者在未来版本中完全移除。

描述

单独的 docker manifest 命令不执行任何操作。要对 manifest 或 manifest 列表进行操作,必须使用其中一个子命令。

单个 manifest 是关于镜像的信息,例如层、大小和摘要。 docker manifest 命令还提供其他信息,例如构建镜像所针对的操作系统和架构。

manifest 列表是通过指定一个或多个(理想情况下多于一个)镜像名称创建的镜像层列表。然后,它可以在 docker pulldocker run 等命令中像镜像名称一样使用。

理想情况下,manifest 列表是使用针对不同 os/arch 组合但功能相同的镜像创建的。因此,manifest 列表通常被称为“多架构镜像”。但是,用户可以创建一个 manifest 列表,指向两个镜像 -- 一个用于 AMD64 上的 Windows,另一个用于 AMD64 上的 Darwin。

manifest inspect

$ docker manifest inspect --help

Usage:  docker manifest inspect [OPTIONS] [MANIFEST_LIST] MANIFEST

Display an image manifest, or manifest list

Options:
      --help       Print usage
      --insecure   Allow communication with an insecure registry
  -v, --verbose    Output additional info including layers and platform

manifest create

Usage:  docker manifest create MANIFEST_LIST MANIFEST [MANIFEST...]

Create a local manifest list for annotating and pushing to a registry

Options:
  -a, --amend      Amend an existing manifest list
      --insecure   Allow communication with an insecure registry
      --help       Print usage

manifest annotate

Usage:  docker manifest annotate [OPTIONS] MANIFEST_LIST MANIFEST

Add additional information to a local image manifest

Options:
      --arch string               Set architecture
      --help                      Print usage
      --os string                 Set operating system
      --os-version string         Set operating system version
      --os-features stringSlice   Set operating system feature
      --variant string            Set architecture variant

manifest push

Usage:  docker manifest push [OPTIONS] MANIFEST_LIST

Push a manifest list to a repository

Options:
      --help       Print usage
      --insecure   Allow push to an insecure registry
  -p, --purge      Remove the local manifest list after push

使用非安全注册表

manifest 命令仅与注册表交互。因此,它无法向引擎查询允许的非安全注册表列表。为了允许 CLI 与非安全注册表交互,一些 docker manifest 命令带有 --insecure 标志。对于每次查询注册表的事务,例如 create,都必须指定 --insecure 标志。此标志告诉 CLI,该注册表调用可能会忽略安全问题,例如缺少证书或自签名证书。同样,向非安全注册表进行 manifest push 时,也必须指定 --insecure 标志。如果在非安全注册表上未使用此标志,则 manifest 命令将无法找到满足默认要求的注册表。

示例

检查镜像的 manifest 对象

$ docker manifest inspect hello-world
{
        "schemaVersion": 2,
        "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
        "config": {
                "mediaType": "application/vnd.docker.container.image.v1+json",
                "size": 1520,
                "digest": "sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57"
        },
        "layers": [
                {
                        "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
                        "size": 972,
                        "digest": "sha256:b04784fba78d739b526e27edc02a5a8cd07b1052e9283f5fc155828f4b614c28"
                }
        ]
}

检查镜像的 manifest 并获取 os/arch 信息

docker manifest inspect 命令接受一个可选的 --verbose 标志,它为您提供镜像名称 (Ref),以及架构和操作系统 (Platform)。

与其他接受镜像名称的 Docker 命令一样,您可以使用或不使用标签引用镜像,或者通过摘要引用(例如 hello-world@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f)。

这是一个使用 --verbose 标志检查镜像 manifest 的示例

$ docker manifest inspect --verbose hello-world
{
        "Ref": "docker.io/library/hello-world:latest",
        "Digest": "sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f",
        "SchemaV2Manifest": {
                "schemaVersion": 2,
                "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
                "config": {
                        "mediaType": "application/vnd.docker.container.image.v1+json",
                        "size": 1520,
                        "digest": "sha256:1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57"
                },
                "layers": [
                        {
                                "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
                                "size": 972,
                                "digest": "sha256:b04784fba78d739b526e27edc02a5a8cd07b1052e9283f5fc155828f4b614c28"
                        }
                ]
        },
        "Platform": {
                "architecture": "amd64",
                "os": "linux"
        }
}

创建并推送 manifest 列表

要创建 manifest 列表,首先在本地使用 create 命令创建 manifest 列表,指定要包含在 manifest 列表中的组成镜像。请记住,这将推送到注册表,因此如果想推送到 Docker 注册表以外的注册表,需要使用注册表名称或 IP 和端口创建 manifest 列表。这类似于标记镜像并将其推送到外部注册表。

创建了 manifest 列表的本地副本后,您可以选择性地对其进行 annotate。允许的 annotation 包括架构和操作系统(覆盖镜像当前值)、操作系统特性以及架构变体。

最后,您需要将 manifest 列表 push 到目标注册表。下面是这三个命令的描述以及一个将它们结合在一起的示例。

$ docker manifest create 45.55.81.106:5000/coolapp:v1 \
    45.55.81.106:5000/coolapp-ppc64le-linux:v1 \
    45.55.81.106:5000/coolapp-arm-linux:v1 \
    45.55.81.106:5000/coolapp-amd64-linux:v1 \
    45.55.81.106:5000/coolapp-amd64-windows:v1

Created manifest list 45.55.81.106:5000/coolapp:v1
$ docker manifest annotate 45.55.81.106:5000/coolapp:v1 45.55.81.106:5000/coolapp-arm-linux --arch arm
$ docker manifest push 45.55.81.106:5000/coolapp:v1
Pushed manifest 45.55.81.106:5000/coolapp@sha256:9701edc932223a66e49dd6c894a11db8c2cf4eccd1414f1ec105a623bf16b426 with digest: sha256:f67dcc5fc786f04f0743abfe0ee5dae9bd8caf8efa6c8144f7f2a43889dc513b
Pushed manifest 45.55.81.106:5000/coolapp@sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f with digest: sha256:b64ca0b60356a30971f098c92200b1271257f100a55b351e6bbe985638352f3a
Pushed manifest 45.55.81.106:5000/coolapp@sha256:39dc41c658cf25f33681a41310372f02728925a54aac3598310bfb1770615fc9 with digest: sha256:df436846483aff62bad830b730a0d3b77731bcf98ba5e470a8bbb8e9e346e4e8
Pushed manifest 45.55.81.106:5000/coolapp@sha256:f91b1145cd4ac800b28122313ae9e88ac340bb3f1e3a4cd3e59a3648650f3275 with digest: sha256:5bb8e50aa2edd408bdf3ddf61efb7338ff34a07b762992c9432f1c02fc0e5e62
sha256:050b213d49d7673ba35014f21454c573dcbec75254a08f4a7c34f66a47c06aba

检查 manifest 列表

$ docker manifest inspect coolapp:v1
{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
   "manifests": [
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 424,
         "digest": "sha256:f67dcc5fc786f04f0743abfe0ee5dae9bd8caf8efa6c8144f7f2a43889dc513b",
         "platform": {
            "architecture": "arm",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 424,
         "digest": "sha256:b64ca0b60356a30971f098c92200b1271257f100a55b351e6bbe985638352f3a",
         "platform": {
            "architecture": "amd64",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 425,
         "digest": "sha256:df436846483aff62bad830b730a0d3b77731bcf98ba5e470a8bbb8e9e346e4e8",
         "platform": {
            "architecture": "ppc64le",
            "os": "linux"
         }
      },
      {
         "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
         "size": 425,
         "digest": "sha256:5bb8e50aa2edd408bdf3ddf61efb7338ff34a07b762992c9432f1c02fc0e5e62",
         "platform": {
            "architecture": "s390x",
            "os": "linux"
         }
      }
   ]
}

推送到非安全注册表

这是一个使用已知非安全注册表创建和推送 manifest 列表的示例。

$ docker manifest create --insecure myprivateregistry.mycompany.com/repo/image:1.0 \
    myprivateregistry.mycompany.com/repo/image-linux-ppc64le:1.0 \
    myprivateregistry.mycompany.com/repo/image-linux-s390x:1.0 \
    myprivateregistry.mycompany.com/repo/image-linux-arm:1.0 \
    myprivateregistry.mycompany.com/repo/image-linux-armhf:1.0 \
    myprivateregistry.mycompany.com/repo/image-windows-amd64:1.0 \
    myprivateregistry.mycompany.com/repo/image-linux-amd64:1.0

$ docker manifest push --insecure myprivateregistry.mycompany.com/repo/image:tag

注意

--insecure 标志对于 annotate manifest 列表不是必需的,因为 annotation 是针对 manifest 列表的本地存储副本进行的。如果在本地存储的 manifest 列表上执行 docker manifest inspect,您也可以跳过 --insecure 标志。请务必记住,本地存储的 manifest 列表在执行 docker pull 时永远不会被引擎使用。

子命令

命令描述
docker manifest annotate向本地镜像 manifest 添加附加信息
docker manifest create创建一个用于 annotation 并推送到注册表的本地 manifest 列表
docker manifest inspect显示镜像 manifest 或 manifest 列表
docker manifest push将 manifest 列表推送到仓库
docker manifest rm从本地存储中删除一个或多个 manifest 列表