Linux服务器Docker卸载某个镜像:
首先输入命令docker images查看当前docker下有多少镜像:
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker images
2 REPOSITORY TAG IMAGE ID CREATED SIZE
3 mysql 5.6 a46c2a2722b9 4 days ago 256MB
4 hello-world latest 4ab4c602aa5e 7 weeks ago 1.84kB
5 morunchang/fastdfs latest a729ac95698a 2 years ago 460MB
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker images
2 REPOSITORY TAG IMAGE ID CREATED SIZE
3 mysql 5.6 a46c2a2722b9 4 days ago 256MB
4 hello-world latest 4ab4c602aa5e 7 weeks ago 1.84kB
5 morunchang/fastdfs latest a729ac95698a 2 years ago 460MB
如上所示可以看到当前docker下有3个镜像:mysql、hello-world、morunchang/fastdfs,现在我们假设要删除hello-world这个镜像,使用如下流程以及命令:
使用命令docker ps -a查看当前运行下的镜像进程:
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker ps -a
2 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3 e061047acf6e mysql:5.6 "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp mysqlserver
4 61c7a4d6363d mysql:5.6 "docker-entrypoint.s…" 2 hours ago Created compassionate_varahamihira
5 024c06fcc1e8 morunchang/fastdfs "sh storage.sh" 3 days ago Up 3 days storage
6 3f2da1b259b5 morunchang/fastdfs "sh tracker.sh" 3 days ago Up 3 days tracker
7 c608062bf46f hello-world "/hello" 4 days ago Exited (0) 4 days ago priceless_keller
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker ps -a
2 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3 e061047acf6e mysql:5.6 "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp mysqlserver
4 61c7a4d6363d mysql:5.6 "docker-entrypoint.s…" 2 hours ago Created compassionate_varahamihira
5 024c06fcc1e8 morunchang/fastdfs "sh storage.sh" 3 days ago Up 3 days storage
6 3f2da1b259b5 morunchang/fastdfs "sh tracker.sh" 3 days ago Up 3 days tracker
7 c608062bf46f hello-world "/hello" 4 days ago Exited (0) 4 days ago priceless_keller
如上所示,我们看到hello-world相关的镜像信息如下:
1 c608062bf46f hello-world "/hello" 4 days ago Exited (0) 4 days ago priceless_keller
然后我们停止hello-world运行的进程,使用如下命令docker stop c608062bf46f:
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker stop c608062bf46f
2 c608062bf46f
停止了镜像的运行后,就可以卸载了。使用命令docker rm c608062bf46f来删除这个镜像。
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker rm c608062bf46f
2 c608062bf46f
这里的“c608062bf46f”是docker ps -a 里面的CONTAINER ID,然后这个镜像就进程就删除。
我们使用docker ps -a命令查看当前进程里面是否还有hello-world相关的进程:
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker ps -a
2 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3 e061047acf6e mysql:5.6 "docker-entrypoint.s…" 2 hours ago Up 2 hours 0.0.0.0:3306->3306/tcp mysqlserver
4 61c7a4d6363d mysql:5.6 "docker-entrypoint.s…" 2 hours ago Created compassionate_varahamihira
5 024c06fcc1e8 morunchang/fastdfs "sh storage.sh" 3 days ago Up 3 days storage
6 3f2da1b259b5 morunchang/fastdfs "sh tracker.sh" 3 days ago Up 3 days tracker
此时发现没有hello-world相关的进程了。
这时我们使用docker images查看下镜像的IMAGE ID,进行最后的删除。
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker images
2 REPOSITORY TAG IMAGE ID CREATED SIZE
3 mysql 5.6 a46c2a2722b9 4 days ago 256MB
4 hello-world latest 4ab4c602aa5e 7 weeks ago 1.84kB
5 morunchang/fastdfs latest a729ac95698a 2 years ago 460MB
使用命令docker rmi 4ab4c602aa5e删除镜像:
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker rmi 4ab4c602aa5e
2 Untagged: hello-world:latest
3 Untagged: hello-world@sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
4 Deleted: sha256:4ab4c602aa5eed5528a6620ff18a1dc4faef0e1ab3a5eddeddb410714478c67f
5 Deleted: sha256:428c97da766c4c13b19088a471de6b622b038f3ae8efa10ec5a37d6d31a2df0b
在使用docker images查看下是否删除掉了hello-world:
1 [root@iZwz9a191mdam4di3dozk3Z ~]# docker images
2 REPOSITORY TAG IMAGE ID CREATED SIZE
3 mysql 5.6 a46c2a2722b9 4 days ago 256MB
4 morunchang/fastdfs latest a729ac95698a 2 years ago 460MB
此时可以看到,hello-world这个镜像删除成功了,已经没有hello-world这个镜像了。
其他的镜像删除也是使用同样的步骤。