Snippet Path

Remove old/extra docker resources

Authors

Containers

Prune unused containers

shell
docker rm $(docker ps -f "status=exited" -aq)

Prune dangling containers created after an specific container

shell
docker rm $(docker ps -f "status=exited" -f "since=node:16-alpine" -aq)

Prune dangling containers created before an specific container

shell
docker rm $(docker ps -f "status=exited" -f "before=node:16-alpine" -aq)

Images

Prune dangling images

shell
docker rmi $(docker images -f "dangling=true" -q)

Prune dangling images created after an specific container

shell
docker rmi $(docker images -f "dangling=true" -f "since=node:16-alpine" -q)

Prune dangling images created before an specific container

shell
docker rmi $(docker images -f "dangling=true" -f "before=node:16-alpine" -q)

Prune images before a timestamp

Beware

The docker image prune command can be buggy sometimes. It might hang and give you no output for a long time. The GitHub issue of this problem opened at 2018, however it is not resolved yet.

shell
docker image prune -a --filter "until=24h"

Volumes

Prune dangling volumes

shell
docker volume rm $(docker volume ls -qf dangling=true)