4.8. 标记镜像
使用 podman tag
命令给本地镜像添加额外的名称。此额外名称可由几个部分组成:<registryhost>/<username>/<name>:<tag>。
先决条件
-
container-tools
元数据包已安装。 - 本地系统上提供了拉取的镜像。
流程
列出所有镜像:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.redhat.io/ubi10/ubi latest 3269c37eae33 7 weeks ago 208 MB
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 使用以下选项之一将
myubi
名称分配给registry.redhat.io/ubi10/ubi
镜像:镜像名称:
podman tag registry.redhat.io/ubi10/ubi myubi
$ podman tag registry.redhat.io/ubi10/ubi myubi
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 镜像 ID:
podman tag 3269c37eae33 myubi
$ podman tag 3269c37eae33 myubi
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 两个命令会给出同样的结果。
列出所有镜像:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.redhat.io/ubi10/ubi latest 3269c37eae33 2 months ago 208 MB localhost/myubi latest 3269c37eae33 2 months ago 208 MB
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 请注意,两个镜像的默认标签都是
latest
。您可以看到所有镜像名称都被分配给单个镜像 ID 3269c37eae33。使用以下方法将
10
标签添加到registry.redhat.io/ubi10/ubi
镜像:镜像名称:
podman tag registry.redhat.io/ubi10/ubi myubi:10
$ podman tag registry.redhat.io/ubi10/ubi myubi:10
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 镜像 ID:
podman tag 3269c37eae33 myubi:10
$ podman tag 3269c37eae33 myubi:10
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 两个命令会给出同样的结果。
验证
列出所有镜像:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.redhat.io/ubi10/ubi latest 3269c37eae33 2 months ago 208 MB localhost/myubi latest 3269c37eae33 2 months ago 208 MB localhost/myubi 10 3269c37eae33 2 months ago 208 MB
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 请注意,两个镜像的默认标签都是
latest
。您可以看到所有镜像名称都被分配给单个镜像 ID 3269c37eae33。
在标记完 registry.redhat.io/ubi10/ubi
镜像后,您有三个选项来运行容器:
-
按 ID (
3269c37eae33
) -
按名称(
localhost/myubi:latest
) -
按名称(
localhost/myubi:10
)