Docker deletes useless containers and mirroring skills

In the process of compiling child images, docker produces many useless containers and images. To delete these contents, it will be very troublesome to delete them one by one. Therefore, some skills are needed to do this.

1. Query the most recent containers

 

#Query the last 5
sudo docker ps -a -n=5

 2. Only output the id of the container

 

 

sudo docker ps -a -q

 3. Delete recent containers in batches

 

 

sudo docker rm $(docker ps -aq -n=5)

 4. Query out the useless mirror

 

 

# -f parameter is the filter condition
sudo docker images -f dangling=true

 5. Delete useless images in batches

 

sudo docker rmi $( docker images -f dangling=true)

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326646745&siteId=291194637