Docker tag命令

docker tag命令教程

docker tag 命令用于用于给镜像打标签。

docker tag命令语法

[root@localhost ~]# docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

案例

镜像打标签

我们使用 docker pull 命令,从 docker 仓库拉取一个 centos 镜像。

[root@localhost ~]# docker pull centos

拉取完成后,终端显示如下:

20 docker tag.png

此时,我们使用 docker images 命令,查看本地镜像列表。

[root@localhost ~]# docker images

终端显示如下:

21 docker tag.png

现在,我们使用 docker run 命令,运行该 centos 镜像。

[root@localhost ~]# docker run -it --name haicoder centos

运行成功,终端显示如下:

22 docker tag.png

现在我们在该镜像里面安装 vim 命令:

[root@7ab550942bd0 /]# yum install -y vim

vim 命令安装成功后,终端显示如下:

23 docker tag.png

我们退出容器,在宿主机使用 docker tag 命令,将我们将安装好 vim 命令的镜像,打一个 tag。

[root@7ab550942bd0 /]# exit exit [root@localhost ~]# docker tag centos centos-vim

现在我们在再次使用 docker images 命令,查看本地镜像列表。

[root@localhost ~]# docker images

终端显示如下:

24 docker tag.png

此时,我们发现本地镜像列表里面多了一个 centos-vim 的镜像,即我们使用 docker tag 命令打包的镜像。

下次再运行容器,我们就可以基于 centos-vim 的镜像来运行。

使用 docker rmi 命令,删除所有的本地镜像。

[root@localhost ~]# docker rmi -f `docker images -q`

docker tag命令总结

docker tag 命令用于用于给镜像打标签。

docker tag命令语法:

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