简体   繁体   中英

How to find running containers using terminal?

I see the following containers running on Docker Desktop application:

在此处输入图像描述

But when I try docker ps on CMD I see nothing as result(empty table) and the result of kubectl get pods is the following:

NAME                               READY   STATUS             RESTARTS      AGE
client-depl-cdf975567-vzgw6        0/1     ImagePullBackOff   7 (34m ago)   12h
comments-depl-76c5bc6948-6fz4s     0/1     ImagePullBackOff   0 (44m ago)   12h
event-bus-depl-69cfbf58f7-slpjc    0/1     ImagePullBackOff   8             12h
moderation-depl-786f4ffc65-kfwh4   0/1     ImagePullBackOff   1 (40m ago)   12h
posts-depl-5f9b5c5774-wjv59        0/1     ImagePullBackOff   11            12h
query-depl-5d7d567fc7-vclfv        0/1     ImagePullBackOff   8             12h

I don't know how to stop the running containers and delete all the images? When I try it using the GUI app they create themselves again automatically.

You need to delete the corresponding workload resource ( Deployment , Statefulset etc) which are controlling your K8s cluster. Workloads by default come with restartPolicy as Always , due to which your Pods are getting recreated after deletion.

To list the a workload resource, run the following command:

# kubectl get <workload-resource name> -A
# -A flag prints the resources present in all namespaces.
kubectl get deploy -A
kubectl get daemonset -A
kubectl get stateful -A

Copy the name of the resource from the printed list and delete it:

kubectl delete <resource-type> <resource-name>
kubectl delete deploy client-depl

you can see all running containers using:

kubectl get deploy -A

for delete them:

kubectl delete deploy client-depl

To delete these you might need to delete deployment, daemonset & statefulsets. If you delete a pod it might just deleted that particular pod but replicas in the deployment will re-spin a new pod hence you should be deleting the deployment.

kubectl get deployment -A lists all the deployment running in your cluster. kubectl get daemonset -A lists all the daemonset running in your cluster. kubectl get statefulset -A lists all the statefulset running in your cluster.

To delete these use kubectl delete deployment <deployment-name> -n <namespace> Similarly replace deployment with statefulset and daemonset to delete that resource.

Once this is done to delete unused images use docker image prune -a this will delete all unused images from your machine. If you need to remove other docker resources like unused containers, newtworks run docker system prune -a

docker system prune document

Images could be delete from Docker desktop as well for doing this refer the below screenshot: 使用 docker desktop 删除悬空和未使用的图像

Delete all pods in a namespace. Make sure you are connected to the right cluster before running this command:

kubectl delete --all pods --namespace=foo

To see all the running Kubernetes container

kubectl get po -o jsonpath='{range .items[*]}{"pod: "}{.metadata.name}{"\n"}{range .spec.containers[*]}{"\tname: "}{.name}{"\n\timage: "}{.image}{"\n"}{end}'

for delete them:

kubectl delete deploy deployment-obj

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM