Docker is an open source application container engine that allows developers to easily create and deploy applications and run them in any environment. One of the benefits of Docker containerized applications is that they run within independent containers, isolated from the host system and avoiding conflicts. However, the number of Docker containers created may be large, and it is easy to produce some unused or abandoned containers. The status of these containers may be "
In this article, we will introduce how to clear the
Before performing the cleanup operation, we need to first determine which containers are marked as "
docker ps -a | grep "<none>"
The output may look like this:
862746adc245 ubuntu:latest "/bin/bash" 5 days ago Up 5 days one-missing-container 9ac7da8db12f centos:7 "/bin/bash" 5 days ago Exited (0) 5 days ago lucid_curie 99e099c008a0 centos:7 "/bin/bash" 5 days ago Exited (0) 5 days ago youthful_elion
In the above output, the first column is the ID of the container, and the second column is the image name of the container. , the third column represents the command of the container, the fourth column represents the creation time of the container, the fifth column represents the running status of the container, and the sixth column represents the name of the container.
It can be seen from the above results that the status of three containers is "
Clearing containers with
docker rm $(docker ps -aq --filter "status=dead" --filter "status=exited" --filter "status=created")
The above command The following actions will be performed:
Please note that if you only want to remove specific stopped containers, you can use docker ps -a | grep "Exited" command to find the IDs of all stopped containers and use docker rm command Delete them.
Once the
docker rmi $(docker images -f "dangling=true" -q)
The above command will select all tagged images from the list and delete them.
Finally, it is recommended that you avoid the
Summary
This article introduces how to clear the
The above is the detailed content of How to clear