Skip to content

Instantly share code, notes, and snippets.

@anton-dealmeida
Forked from bastman/docker-cleanup-resources.md
Last active September 13, 2022 12:37
Show Gist options
  • Save anton-dealmeida/f8bdfc0b9640000ae3c9cd061f608cb6 to your computer and use it in GitHub Desktop.
Save anton-dealmeida/f8bdfc0b9640000ae3c9cd061f608cb6 to your computer and use it in GitHub Desktop.
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) ...

This is forked from here

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes    
$ 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: http://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images

$ 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 }')

remove docker containers

// see: http://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images

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

Resize disk space for docker vm

$ docker-machine create --driver virtualbox --virtualbox-disk-size "40000" default

Docker Troubleshooting

Read the container logs

$ docker logs -f <container_name/container_id>

"SSH" into the container

$ docker exec -it <container_name> <command>
$ docker exec -it myContainer /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment