docker 清除无用的容器和无用的镜像
一.清除无用的容器
以前linux主机down机后,每次使用docker run 镜像时会产生一个容器(这种操作是错误的,正确的方法是找到容器id,再启动就行了),久而久之,里面有了很多无用的容器,如下所示:
docker container ls --all
如下图所示:keycloak有很多容器,实际在用的只有容器ID:1c50开头的,需要删除其它没有在用的。
[root@iZwz97yqubb71vyxhuskfwZ tmp]# docker rm -f e5b2bf70cc60 e5b2bf70cc60 [root@iZwz97yqubb71vyxhuskfwZ tmp]# docker rm -f 4ac2ae1cc92f 4ac2ae1cc92f [root@iZwz97yqubb71vyxhuskfwZ tmp]# docker rm -f ccaff94e1b03 ccaff94e1b03 [root@iZwz97yqubb71vyxhuskfwZ tmp]# docker rm -f fc2e2bee3bd9 fc2e2bee3bd9 [root@iZwz97yqubb71vyxhuskfwZ tmp]# docker rm -f 90a739dd9724 90a739dd9724
二.清除无用的镜像
[root@iZwz97yqubb71vyxhuskfwZ tmp]# docker images --all REPOSITORY TAG IMAGE ID CREATED SIZE quay.io/keycloak/keycloak 20.0.1 ee732828e555 3 weeks ago 557MB ubuntu latest a8780b506fa4 3 weeks ago 77.8MB hello-world latest feb5d9fea6a5 14 months ago 13.3kB scrapinghub/splash latest 9364575df985 2 years ago 1.89GB
下面命令不会删除有容器依赖的镜像,安全一些
docker rmi a8780b506fa4
三.删除提示: image is referenced in multiple repositories
[root@dev-data-node001 scrapyrt-master]# docker rmi 344975c421cea Error response from daemon: conflict: unable to delete 344975c421ce (must be forced) - image is referenced in multiple repositories
解决方案:删除指定的tag,如下所示
[root@dev-data-node001 scrapyrt-master]# docker rmi hushaoren/myscrapyrt:1.2