docker tag 用于给镜像打标签,语法以下:docker
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
① 好比我如今有一个 centos 镜像:centos
[root@localhost ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 1e1148e4cc2c 2 weeks ago 202MB
② 我对 centos 进行开发,开发了第一个版本,我就能够对这个版本打标签,打完标签后会生成新的镜像:spa
[root@localhost ~]$ docker tag centos centos:v1
[root@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 1e1148e4cc2c 2 weeks ago 202MB centos v1 1e1148e4cc2c 2 weeks ago 202MB
③ 我继续对 centos 进行开发,开发了第二个版本,继续打标签:code
[root@localhost ~]$ docker tag centos centos:v2
[root@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 1e1148e4cc2c 2 weeks ago 202MB centos v1 1e1148e4cc2c 2 weeks ago 202MB centos v2 1e1148e4cc2c 2 weeks ago 202MB
④ 以此类推,每开发一个版本打一个标签,若是之后我想回滚版本,就可使用指定标签的镜像来建立容器:blog
[root@localhost ~]$ docker run -itd centos:v1