Docker tag命令

本文将介绍docker tag命令。

标记本地镜像,将其归入某一仓库。帮助信息如下:

hxstrive@localhost:~/Desktop$ docker tag --help

Usage:  docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

其中:

  • SOURCE_IMAGE 表示源镜像名称

  • TARGET_IMAGE 表示目标镜像名称

  • [:TAG] 表示TAG名称,这是可选的

实例1:为指定的容器(不指定tag,默认为latest)生成一个标记。

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              4c108a37151f        4 weeks ago         64.2MB
centos              latest              9f38484d220f        4 months ago        202MB
hello-world         latest              fce289e99eb9        6 months ago        1.84kB
[root@localhost ~]# docker tag ubuntu myubuntu:v16
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
myubuntu            v16                 4c108a37151f        4 weeks ago         64.2MB
ubuntu              latest              4c108a37151f        4 weeks ago         64.2MB
centos              latest              9f38484d220f        4 months ago        202MB
hello-world         latest              fce289e99eb9        6 months ago        1.84kB

首先使用“docker images”查看本机docker存有哪些镜像;使用“docker tag ubuntu myubuntu:v16”或“docker tag ubuntu:latest myubuntu:v16”去创建一个新的tag;然后再次使用“docker images”查看镜像列表。

实例2:为指定的容器和版本生成一个用户自定义的标记。

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              4c108a37151f        4 weeks ago         64.2MB
centos              6.7                 9f1de3c6ad53        4 months ago        191MB
[root@localhost ~]# docker tag centos:6.7 mycentos:v6.7
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              4c108a37151f        4 weeks ago         64.2MB
centos              6.7                 9f1de3c6ad53        4 months ago        191MB
mycentos            v6.7                9f1de3c6ad53        4 months ago        191MB

上面我们有一个centos:6.7的镜像,使用“docker tag centos:6.7 mycentos:v6.7”生成一个新的标记“mycentos:v6.7”镜像。

实例3:删除自定义的tag。下面将删除“mycentos:v6.7”自定义的tag。

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              4c108a37151f        4 weeks ago         64.2MB
centos              6.7                 9f1de3c6ad53        4 months ago        191MB
mycentos            v6.7                9f1de3c6ad53        4 months ago        191MB
[root@localhost ~]# docker rmi mycentos
Error: No such image: mycentos
[root@localhost ~]# docker rmi mycentos:v6.7
Untagged: mycentos:v6.7
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              4c108a37151f        4 weeks ago         64.2MB
centos              6.7                 9f1de3c6ad53        4 months ago        191MB

注意:上面直接使用“docker rmi mycentos”语句删除镜像失败了,因为该语句默认将删除latest的版本,但是我们没有改版本的镜像。需要我们手动指定版本“docker rmi mycentos:v6.7”。

总结:使用docker tag创建的目标和一般的docker镜像没有什么区别,也能使用docker rmi、docker run进行操作。

成熟不是人的心变老,而是泪在眼眶里打转还能微笑。
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号