4.7. 标记镜像

使用 podman tag 命令给本地镜像添加额外的名称。此额外名称可由几个部分组成:<registryhost>/<username>/<name>:<tag>

先决条件

  • container-tools 元数据包已安装。
  • 本地系统上提供了拉取的镜像。

流程

  1. 列出所有镜像:

    $ podman images
    REPOSITORY                           TAG     IMAGE ID      CREATED      SIZE
    registry.redhat.io/ubi9/ubi          latest  3269c37eae33  7 weeks ago  208 MB
  2. 使用以下选项之一将 myubi 名称分配给 registry.redhat.io/ubi9/ubi 镜像:

    • 镜像名称:

      $ podman tag registry.redhat.io/ubi9/ubi myubi
    • 镜像 ID:

      $ podman tag 3269c37eae33 myubi

      两个命令会给出同样的结果。

  3. 列出所有镜像:

    $ podman images
    REPOSITORY                           TAG     IMAGE ID      CREATED       SIZE
    registry.redhat.io/ubi9/ubi          latest  3269c37eae33  2 months ago  208 MB
    localhost/myubi                      latest  3269c37eae33  2 months ago  208 MB

    请注意,两个镜像的默认标签都是 latest。您可以看到所有镜像名称都被分配给单个镜像 ID 3269c37eae33。

  4. 使用以下方法将 9 标签添加到 registry.redhat.io/ubi9/ubi 镜像:

    • 镜像名称:

      $ podman tag registry.redhat.io/ubi9/ubi myubi:9
    • 镜像 ID:

      $ podman tag 3269c37eae33 myubi:9

      两个命令会给出同样的结果。

  5. 列出所有镜像:

    $ podman images
    REPOSITORY                           TAG     IMAGE ID      CREATED       SIZE
    registry.redhat.io/ubi9/ubi          latest  3269c37eae33  2 months ago  208 MB
    localhost/myubi                      latest  3269c37eae33  2 months ago  208 MB
    localhost/myubi                      9     3269c37eae33  2 months ago  208 MB

    请注意,两个镜像的默认标签都是 latest。您可以看到所有镜像名称都被分配给单个镜像 ID 3269c37eae33。

在标记 registry.redhat.io/ubi9/ubi 镜像后,您有三个选项来运行容器:

  • 按 ID (3269c37eae33)
  • 按名称(localhost/myubi:latest)
  • 按名称 (localhost/myubi:9)

其他资源

  • podman-tag man page