How to batch Delete stopped containers in Docker
How to batch Delete stopped containers in Docker
Method 1:
# Display all containers, filter out Exited containers, and retrieve the IDs of these containers,
# Sudo docker ps-a | grep Exited | awk '{print $1 }'
# Query all containers, filter out Exited containers, list container IDs, and delete these containers
# Sudo docker rm docker ps-a | grep Exited | awk '{print $1 }'
Method 2:
# Delete all containers that are not running (if they are not running, they will be deleted together)
# Sudo docker rm $ (sudo docker ps-a-q)
Method 3:
# Delete the Exited container Based on the container status
# Sudo docker rm $ (sudo docker ps-qf status = exited)
Method 4:
# After Docker 1.13, you can use the docker containers prune command to delete isolated containers.
Sudo docker container prune
# Deleting all images
Sudo docker rmi $ (docker images-q)
Figure:
02-delete all containers. All containers that are not running are deleted. Running containers cannot be deleted to delete unnecessary containers.
03-Docker versions earlier than 1.13 can be deleted based on the container status.
04-query all containers and filter out containers in the Exited status.
05-Docker 1.13 and later versions start to support the prune command to quickly delete the exited container
Delete all stopped containers:
# Docker system prune
02-delete all containers. All containers that are not running are deleted. Running containers cannot be deleted to delete unnecessary containers.
03-Docker versions earlier than 1.13 can be deleted based on the container status.
04-query all containers and filter out containers in the Exited status.
05-Docker 1.13 and later versions start to support the prune command to quickly delete the exited container
# Docker container prune
For more Docker tutorials, see the following:
Docker installation application (CentOS 6.5_x64)
Configure Docker on Ubuntu 16.04 Server
Install Docker in Ubuntu 15.04
Docker installation instance
Create a basic image using Docker
How to install Docker on Ubuntu 15.04 and its basic usage
Docker usage notes on Ubuntu 16.04
Use Docker to start common applications in minutes
Solution for changing the configuration file of Docker in Ubuntu 16.04 does not take effect
Docker details: click here
Docker: click here