docker tag 用於給鏡像打標簽,語法如下:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
① 比如我現在有一個 centos 鏡像:
[root@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos latest 1e1148e4cc2c 2 weeks ago 202MB
② 我對 centos 進行開發,開發了第一個版本,我就可以對這個版本打標簽,打完標簽后會生成新的鏡像:
[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 進行開發,開發了第二個版本,繼續打標簽:
[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
④ 以此類推,每開發一個版本打一個標簽,如果以后我想回滾版本,就可以使用指定標簽的鏡像來創建容器:
[root@localhost ~]$ docker run -itd centos:v1