Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see:

docker volume rm $(docker volume ls -qf dangling=true)
docker volume ls -qf dangling=true | xargs -r docker volume rm

delete networks

$ docker network ls  
$ docker network ls | grep "bridge"   
$ docker network rm $(docker network ls | grep "bridge" | awk '/ / { print $1 }')

remove docker images

// see:

docker images
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)

docker images | grep "none"
docker rmi $(docker images | grep "none" | awk '/ / { print $3 }')

docker image prune -f

# you can also add this to cron:
echo '33 3 * * * root docker image prune -f'  >> /etc/crontab

remove STOPPED containers

// see:

$ docker ps
$ docker ps -a
$ docker rm $(docker ps -qa --no-trunc --filter "status=exited")

remove OLD stopped containers

# based on
docker ps --filter "status=exited" | grep 'months ago\|weeks ago\|years ago' | awk '{print $1}' | awk '{print $1}' | xargs --no-run-if-empty docker rm

Resize disk space for docker vm

$ docker-machine create --driver virtualbox --virtualbox-disk-size "40000" default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment