Low disk space Docker container increasing in size everyday

I have installed mongodb and meteor on an Amazon Instance EC2. my main challenge is that the container is increasing in size everyday and am running in short of disk space. I really need your assistance here, am running in short of disk space now.

I probably won’t have a great solution for you, but what I do is delete the whole Docker installation along with /var/lib/docker (I think this has all the images) and then reinstall it. Suffices me for more than a month.

erase the logs, or make a dump of the DB and reinstall it.

Linux maintenance is not easy :slight_smile:

If you run this

docker rm -v $(docker ps -a -q -f status=exited)

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

docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes

You should get some space back.

1 Like

Thanks guys for assisting i got a solution on:-

Thanks a lot, these command helped me to get from 100% disk space to 57%. Fantastic! :slight_smile: Would you mind explaining a bit what these commands actually do?

1 Like

Sure!

docker rm -v ...

This command is saying docker remove the following containers and their associated volumes.

$(docker ps -a -q -f status=exited)

This command says show me the list of docker process ids with the filter of exited containers only.

Together it’s removing all exited Docker containers and their volumes.

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

This command removes all the “dangling” images which in my experience is the greatest cause of disk usage with docker. These images have to do with the way the storage engine is set up. You are either using AUFS if you’re on Ubuntu 14.04 or maybe Overlay or Overlay2 if you’re on Ubuntu 16.04. Regardless, every time you pull a new image onto your machine it has to pull a bunch of additional images which aren’t needed afterward that just take up space if you don’t delete them.

The last command can be replaced with the following for versions of docker >= 1.9

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

Both commands do the same thing, delete abandoned volumes. In the first step we deleted the volumes with the containers, but if you don’t delete their volumes then they will stick around until you delete them.

Volumes, images, and containers take up a majority of space on your machine, but you may also want to consider looking at the size of your log files as well by running the following.

sudo su -
cd /var/lib/docker/containers
du -hs .

If you notice the usage is high cd into the directory with high usage and clean out the log file.

2 Likes

Hey, thanks for the great answer, highly appreciated!

1 Like

Hey Kris, that tip was awesome, thank you!
Gustavo.

1 Like