Linux删除repo镜像,K8S镜像删除及环境清理
环境清理:#删除所有容器sudo docker rm -f $(sudo docker ps -qa)#删除/var/etcd目录sudo rm -rf /var/etcd#删除/var/lib/kubelet/目录,删除前先卸载for m in $(sudo tac /proc/mounts | sudo awk '{print $2}'|sudo grep /var/lib/kubelet);
环境清理:
#删除所有容器
sudo docker rm -f $(sudo docker ps -qa)
#删除/var/etcd目录
sudo rm -rf /var/etcd
#删除/var/lib/kubelet/目录,删除前先卸载
for m in $(sudo tac /proc/mounts | sudo awk '{print $2}'|sudo grep /var/lib/kubelet);do
sudo umount $m||true
done
sudo rm -rf /var/lib/kubelet/
#删除/var/lib/rancher/目录,删除前先卸载
for m in $(sudo tac /proc/mounts | sudo awk '{print $2}'|sudo grep /var/lib/rancher);do
sudo umount $m||true
done
sudo rm -rf /var/lib/rancher/
#删除/run/kubernetes/ 目录
sudo rm -rf /run/kubernetes/
#删除所有的数据卷
sudo docker volume rm $(sudo docker volume ls -q)
#再次显示所有的容器和数据卷,确保没有残留
sudo docker ps -a
sudo docker volume ls
镜像删除:
1. 首先查看镜像
[root@docker-vp1 nexus-3.1.0-04]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins 2.19.4 ff6f0851ef57 2 weeks ago 714.1 MB
jenkins/jenkins 2.19.4 ff6f0851ef57 2 weeks ago 714.1 MB
192.168.1.110/centos/centos 7.2 38ea04e19303 12 months ago 194.6 MB
192.168.1.111/centos/centos 7.2 38ea04e19303 12 months ago 194.6 MB
2. 删除其中一个镜像,这里的镜像有两个repo引用,并且没有容器使用
[root@docker-vp1 nexus-3.1.0-04]# docker rmi 38ea04e19303
Error response from daemon: conflict: unable to delete 38ea04e19303 (must be forced) - image is referenced in one or more repositories
出现上面问题的原因:
对于被删除的ImageID,这里存在多个REPOSITORY名字引用,解决方法如下:
[root@docker-vp1 nexus-3.1.0-04]# docker rmi 192.168.1.111/centos/centos:7.2
Untagged: 192.168.1.111/centos/centos:7.2
Untagged: 192.168.1.111/centos/centos@sha256:05c5e4ffbd3e4e54a685915394858e1dacc38873f02920b57b66551a1626dbd3
即删除时指定名称,而不是IMAGE ID。
然后再删除IMAGE ID就可以了:
[root@docker-vp1 nexus-3.1.0-04]# docker rmi 38ea04e19303
Untagged: 192.168.1.110/centos/centos:7.2
Untagged: 192.168.1.110/centos/centos@sha256:05c5e4ffbd3e4e54a685915394858e1dacc38873f02920b57b66551a1626dbd3
Deleted: sha256:38ea04e1930337de1455fed8651fcc9a029805f4559af44558ba9702340ce1e2
Deleted: sha256:aa62a869f8107ec47faa7ad18eded96b051c249cd2f4a5d0d1bca8baf2757358
Deleted: sha256:3c74eb540809de9dbddebd4681781bb1b6145c981756472cd67c6e3eb7704801
Deleted: sha256:feba031447e29ed7d0f316065820e466ba91a258f3b2e68f8e21e940bc45b5cd
Deleted: sha256:3d3648a4ed44853a2231971a1bccf855b83809767558e164bfebbea079d40c34
Deleted: sha256:322e89546b1db8134d2a5b057779843aa80877705ce70e1182f20f94bf31a43d
Deleted: sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
3. 继续查看剩余的镜像
[root@docker-vp1 nexus-3.1.0-04]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins/jenkins 2.19.4 ff6f0851ef57 2 weeks ago 714.1 MB
jenkins 2.19.4 ff6f0851ef57 2 weeks ago 714.1 MB
更多推荐
所有评论(0)