删除镜像时:
1、先停掉镜像相关容器
2、删除容器
3、删除镜像
例如:删除如下镜像
[root@tcy1 dockerfile]#index.tenxcloud.com/docker_library/elasticsearch:1.6
查看容器:
[root@tcy1 dockerfile]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1aef3e91ffdd elasticsearch "/docker-entrypoint. 6 minutes ago tender_shockley
e925b1456341 elasticsearch "/docker-entrypoint. 14 minutes ago Up 14 minutes 9200/tcp, 0.0.0.0:9300->9300/tcp tender_bohr
baa96befcccb index.tenxcloud.com/docker_library/elasticsearch:1.6 "/docker-entrypoint. 41 minutes ago Exited (143) 55 seconds ago hopeful_leakey
ef3e81c343c1 nginx "nginx -g 'daemon of 24 hours ago Exited (0) 23 hours ago 0.0.0.0:80->80/tcp gloomy_babbage
a3fca27221d7 alpine "sh" 24 hours ago Exited (0) 24 hours ago cranky_brattain
查看镜像:
[root@tcy1 dockerfile]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
elasticsearch latest a62bcf85821b 13 days ago 485.9 MB
nginx latest 01133ef0d8b6 3 weeks ago 108.9 MB
alpine latest 9797e5e798a0 4 months ago 4.143 MB
openjdk 8u121-jre-alpine db5e9a31133b 12 months ago 81.35 MB
index.tenxcloud.com/docker_library/elasticsearch 1.6 ab26ba8ca1c5 22 months ago 347 MB
镜像ID和容器ID是不一样的
1、先停掉镜像相关容器
[root@tcy1 dockerfile]# docker stop baa96befcccb
2、删除容器
[root@tcy1 dockerfile]# docker rm baa96befcccb
3、删除镜像
[root@tcy1 dockerfile]# docker rmi ab26ba8ca1c5