how to clean up docker overlay directory?

2020-05-11 21:09发布

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?

9条回答
Lonely孤独者°
2楼-- · 2020-05-11 22:00

Docker garbage collection can be done in an easy way using another docker container https://github.com/spotify/docker-gc

You could make it run as a cron using https://github.com/flaccid/docker-docker-gc-crond

查看更多
Anthone
3楼-- · 2020-05-11 22:05

Here is a working option:

docker rm -f $(docker ps -a |awk 'NR>1&&/Exited/{print $1}')
查看更多
Emotional °昔
4楼-- · 2020-05-11 22:07

BE CAREFUL, this solutions seems remove other important stuffs.

You need inspect your images/containers and remove the folders in /opt/docker/overlay that wasn't found in inspect's execution

docker inspect $(docker ps -qa) | grep -oE '[a-f0-9]{64}' >> inspect-hashs.txt

docker inspect $(docker images -qa) | grep -oE '[a-f0-9]{64}' >> inspect-hashs.txt

sudo ls -l /var/lib/docker/overlay > overlays.txt

diff -u  inspect-hashs.txt overlays.txt | grep -E '^\+' | grep -oE '[a-f0-9]{64}' | xargs sudo rm -rf /opt/docker/overlay/
查看更多
登录 后发表回答