Common commands for Docker batch cleanup and deletion of images and containers

Common commands for Docker batch cleanup and deletion of images and containers

1. Clear images that are more than 36 hours old than their creation time.

docker image prune -a --filter "until=36h"

2. Clear all stopped containers, except those created within 36 hours.

docker container prune --filter "until=36h"

3. Clean up all volumes except lable=keep (no referenced volumes)

docker volume prune --filter "label!=keep"

4. Clean everything: images, containers, networks one-time cleaning operation

docker system prune

5. Delete all images that are not running containers

docker images | awk '{print $3}' | xargs docker rmi

6. Delete the image whose tag is none and does not run the container.

docker images | grep none | awk '{print $3}' | xargs docker rmi

7. Stop all running containers

docker ps -a | awk '{print $1}' | xargs docker stop

8. Delete all stopped containers

docker ps -a | awk '{print $1}' | xargs docker rm

Guess you like

Origin blog.csdn.net/ChennyWJS/article/details/131702193