docker manifest

說明管理 Docker 映像檔資訊清單和資訊清單列表
用法docker manifest COMMAND

實驗性

此指令為實驗性功能。

實驗性功能旨在供測試和回饋使用,因為它們的功能或設計可能會在版本之間發生變化,恕不另行通知,或者在未來的版本中可能會被完全移除。

說明

docker manifest 指令本身不執行任何操作。要對資訊清單或資訊清單列表進行操作,必須使用其中一個子指令。

單一資訊清單是關於映像檔的資訊,例如:層、大小和摘要。docker manifest 指令還會提供額外資訊,例如映像檔建置的作業系統和架構。

資訊清單列表是透過指定一個或多個(最好是多個)映像檔名稱建立的映像檔層列表。然後,它可以在 docker pulldocker run 指令中以與映像檔名稱相同的方式使用。

理想情況下,一個 manifest 清單是由功能相同但適用於不同作業系統/架構組合的映像檔所建立。因此,manifest 清單通常被稱為「多架構映像檔」。然而,使用者可以建立一個 manifest 清單,指向兩個映像檔:一個適用於 AMD64 架構的 Windows,另一個適用於 AMD64 架構的 Darwin。

manifest inspect(檢查 manifest)

$ 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(建立 manifest)

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(註釋 manifest)

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(推送 manifest)

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

使用不安全的 Registry

manifest 指令僅與 Registry 互動。因此,它無法查詢引擎以取得允許的不安全 Registry 清單。為了允許 CLI 與不安全的 Registry 互動,一些 docker manifest 指令具有 --insecure 旗標。對於每個查詢 Registry 的事務(例如 create),都必須指定 --insecure 旗標。這個旗標告訴 CLI,這個 Registry 呼叫可能會忽略安全性問題,例如缺少或自簽憑證。同樣地,在將 manifest push 到不安全的 Registry 時,也必須指定 --insecure 旗標。如果在使用不安全的 Registry 時未指定此旗標,manifest 指令將無法找到符合預設要求的 Registry。

範例

檢查映像檔的 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 並取得作業系統/架構資訊

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 清單,您首先要透過指定您希望包含在 manifest 清單中的組成映像檔,在本地端 create manifest 清單。請記住,這會被推送至 Registry,因此如果您要推送至 Docker Registry 以外的 Registry,則需要使用 Registry 名稱或 IP 和埠來建立 manifest 清單。這類似於標記映像檔並將其推送至外部 Registry。

建立 manifest 清單的本地副本後,您可以選擇性地 annotate 它。允許的註釋包括架構和作業系統(覆蓋映像檔的目前值)、作業系統功能和架構變體。

最後,您需要將 manifest 清單 push 到所需的 Registry。以下是這三個指令的說明,以及一個將它們組合在一起的範例。

$ 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"
         }
      }
   ]
}

推送至不安全的 Registry

以下是如何使用已知的不安全 Registry 建立和推送 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

注意事項

註釋 manifest 清單不需要 --insecure 旗標,因為註釋是針對 manifest 清單的本地儲存副本。如果您正在對本地儲存的 manifest 清單執行 docker manifest inspect,也可以略過 --insecure 旗標。請務必記住,在執行 docker pull 時,引擎永遠不會使用本地儲存的 manifest 清單。

子指令

指令說明
docker manifest annotate將額外資訊新增至本地映像檔 manifest
docker manifest create建立用於註釋和推送至 Registry 的本地 manifest 清單
docker manifest inspect顯示映像檔 manifest 或 manifest 清單
docker manifest push將 manifest 清單推送至儲存庫
docker manifest rm從本地儲存空間中刪除一個或多個 manifest 清單