Sanitize Docker Environment


This post is in the category: Tips

Random small break-fix or enlightening ideas


I have a few docker hosts used for development, and sometimes I need to clean out all images/containers/network groups and start from scratch. These commands do just that. Obviously don’t run these on any machines w/ persistent data. Use with caution!

Linux Hosts (no Docker GUI)

Relatively safe cleanup – these commands remove dangling images/volumes that are likely no longer used and just taking up space.

#[root]$ docker system prune -f
#[root]$ docker rmi $(docker images -f "dangling=true" -q)
#[root]$ docker volume rm $(docker volume ls -q -f dangling=true)

More destructive,

#[root]$ docker kill $(docker ps -a -q)
#[root]$ docker rm $(docker ps -a -q)
#[root]$ docker rmi $(docker images -q) -f

MacOS Hosts (Docker GUI)

I’ve had times where the Docker image completely fills up, and cleaning up images to not free up space. So it’s just easier to delete the Virtualbox image and restart Docker.

Delete the Docker VM disk file:

[user]$ rm -f ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

Restart Docker using the Docker GUI.

This entry was posted in Tips on by .

About Andrew Wells

I have been developing on the LAMP stack since about 2006. I run Ubuntu XFCE on my desktop and have a history of managing Ubuntu and CentOS servers. I code web applications mostly in PHP but have experience with other languages as well. When I'm not working, I can be found working in my home lab or out snowboarding, hiking, camping, or biking depending on the season.

Leave a Reply

Your email address will not be published. Required fields are marked *