[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f6d0b4767a6c 2 months ago 133MB
[root@localhost docker]# docker tag nginx:latest nginx:test #添加新标签[root@localhost docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f6d0b4767a6c 2 months ago 133MB
nginx test f6d0b4767a6c 2 months ago 133MB #新标签镜像#此时不能使用镜像ID删除镜像,可以通过标签删除任一镜像
七、镜像备份
cd /opt/ #存放在此目录中
docker save -o xyw_nginx nginx:latest #镜像备份,文件名为xyw_nginx
docker load < xyw_nginx #载入镜像
docker --input xyw_nginx #载入镜像
[root@localhost docker]# docker images #此时镜像存在
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f6d0b4767a6c 2 months ago 133MB
nginx test f6d0b4767a6c 2 months ago 133MB
[root@localhost docker]# cd /opt/[root@localhost opt]# docker save -o xyw_nginx nginx:latest #镜像备份[root@localhost opt]# ls
containerd rh xyw_nginx
[root@localhost opt]# ll -h
总用量 131M
drwx--x--x. 4 root root 28 3月 22 14:45 containerd
drwxr-xr-x. 2 root root 6 3月 26 2015 rh
-rw-------. 1 root root 131M 3月 22 15:56 xyw_nginx #备份的镜像文件[root@localhost opt]# docker rmi nginx:latest #删除原有镜像
Untagged: nginx:latest
[root@localhost opt]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx test f6d0b4767a6c 2 months ago 133MB
[root@localhost opt]# docker rmi f6d0b4767a6c #继续删除
Untagged: nginx:test
Untagged: nginx@sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa
Deleted: sha256:f6d0b4767a6c466c178bf718f99bea0d3742b26679081e52dbf8e0c7c4c42d74
Deleted: sha256:4dfe71c4470c5920135f00af483556b09911b72547113512d36dc29bfc5f7445
Deleted: sha256:3c90a0917c79b758d74b7040f62d17a7680cd14077f734330b1994a2985283b8
Deleted: sha256:a1c538085c6f891424160d8db120ea093d4dda393e94cd4713e3fff3c82299b5
Deleted: sha256:a3ee2510dcf02c980d7aff635909612006fd1662084d6225e52e769b984abeb5
Deleted: sha256:cb42413394c4059335228c137fe884ff3ab8946a014014309676c25e3ac86864
[root@localhost opt]# docker images #此时已没有镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@localhost opt]# docker load < xyw_nginx #恢复镜像
cb42413394c4: Loading layer 72.51MB/72.51MB
1c91bf69a08b: Loading layer 64.6MB/64.6MB
56bc37de0858: Loading layer 3.072kB/3.072kB
3e5288f7a70f: Loading layer 4.096kB/4.096kB
85fcec7ef3ef: Loading layer 3.584kB/3.584kB
Loaded image: nginx:latest
[root@localhost opt]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest f6d0b4767a6c 2 months ago 133MB