環境清理:docker
#刪除全部容器
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 lscentos
鏡像刪除:3d
1. 首先查看鏡像kubernetes
- [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引用,而且沒有容器使用jenkins
- [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名字引用,解決方法以下:it
- [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。class
而後再刪除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. 繼續查看剩餘的鏡像awk
- [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