Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to clean up docker overlay directory?

I'm running docker via CoreOS and AWS's ECS. I had a failing image that got restarted many times, and the containers are still around- they filled my drive partition. Specifically, /var/lib/docker/overlay/ contains a large number of files/directories.

I know that docker-cleanup-volumes is a thing, but it cleans the /volumes directory, not the /overlay directory.

docker ps -a shows over 250 start attempts on my bad docker container. They aren't running, though.

Aside from rm -rf /var/lib/docker/overlay/*, how can I/should I clean this up?

like image 634
tedder42 Avatar asked Jul 29 '15 22:07

tedder42


2 Answers

From our side we used:

sudo docker system prune -a -f

Which saved me 3Go!

We also used the famous commands:

sudo docker rm -v $(sudo docker ps -a -q -f status=exited)
sudo docker rmi -f  $(sudo docker images -f "dangling=true" -q)
docker volume ls -qf dangling=true | xargs -r docker volume rm

We put that on cron to manage a little bit more efficently our disk space.

Reference: https://forums.docker.com/t/some-way-to-clean-up-identify-contents-of-var-lib-docker-overlay/30604/4

like image 90
user3774109 Avatar answered Oct 28 '22 19:10

user3774109


Here's the hacky way I'm doing this right now. I'm not going to accept it as an answer because I'm hoping there's a better way.

# delete old docker processes
docker rm `docker ps -a | grep Exited | awk '{print $1 }'`
  ignore_errors: true

# delete old images. will complain about still-in-use images.
docker rmi `docker images -aq`
like image 14
tedder42 Avatar answered Oct 28 '22 19:10

tedder42