清除 docker/podman/kubernetes 的資源

 

測試時,常常會建一大堆的物件,這時就需要清除全部資源。

 

docker環境的清除:

[root@docker ~]# cat docker_cleanall.sh
#!/bin/bash
# 2019.1.16 Wed Anderson Version 0.0.1
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker rmi -f $(docker images -aq)
[root@docker ~]# ./docker_cleanall.sh
"docker stop" requires at least 1 argument(s).
See 'docker stop --help'.

Usage:  docker stop [OPTIONS] CONTAINER [CONTAINER...]

Stop one or more running containers
"docker rm" requires at least 1 argument(s).
See 'docker rm --help'.

Usage:  docker rm [OPTIONS] CONTAINER [CONTAINER...]

Remove one or more containers
"docker rmi" requires at least 1 argument(s).
See 'docker rmi --help'.

Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images
[root@docker ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@docker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

 

podman 的清除:

[root@docker ~]# cat podman_cleanall.sh
#!/bin/bash
# 2020.3.17 Tue Anderson Version 0.0.1
# remove all containers+container images
podman stop -a
podman rm -a
podman rmi -a
[root@docker ~]# ./podman_cleanall.sh
[root@docker ~]#
[root@docker ~]# podman ps
CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES
[root@docker ~]# podman ps -a
CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES
[root@docker ~]# podman images
REPOSITORY   TAG   IMAGE ID   CREATED   SIZE

 

kubernetes(k8s)的清除:

[root@master ~]# cat kube_clean_all.sh
#!/bin/bash
# 2020.8.28 Fri Version 0.0.1
#               Anderson Wang
kubectl delete service --all
kubectl delete deployment --all
kubectl delete pod --all
kubectl delete pv --all
kubectl delete pvc --all
kubectl delete secrets --all
kubectl delete configmaps --all
[root@master ~]# ./kube_clean_all.sh
service "kubernetes" deleted
No resources found
No resources found
No resources found
No resources found
secret "default-token-29lmv" deleted
No resources found
本篇發表於 Bookmark, CentOS 6, CentOS 7, CentOS 8, 網路, Docker, kubernetes, Linux, RHEL 6, RHEL 7, RHEL 8, ubuntu。將永久鏈結加入書籤。

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Google photo

您的留言將使用 Google 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s