shekhargulati / 52-technologies-in-2016

Let's learn a new technology every week. A new technology blog every Sunday in 2016.
https://shekhargulati.com/
MIT License
7.21k stars 596 forks source link

Week 39: Docker for Java Developers Part 1 #60

Open shekhargulati opened 8 years ago

shekhargulati commented 8 years ago

Please provide your feedback by posting a comment against this issue.

soleo commented 8 years ago

When you are building all kinds of docker images, you may end up with a lot of untagged images, volumes. A trick I used in my own projects is a bash function like this.

# docker clean up, remove all stopped containers and untagged images
# http://jimhoskins.com/2013/07/27/remove-untagged-docker-images.html
# https://github.com/chadoe/docker-cleanup-volumes
# https://www.calazan.com/docker-cleanup-commands/
docker-cleanup() {
    docker rm $(docker ps -a -q);
    docker rmi $(docker images -q -f dangling=true);
    docker volume rm $(docker volume ls -qf dangling=true)
}

Most of the times, just removing the stopped containers is good enough. But it's nice to have something to clean up locally.

shekhargulati commented 8 years ago

@soleo thanks. I have added it to the blog.