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?
We just started having this problem, and btafarelo's answer got me part of the way, or at least made me feel better about removing the sha256 entries.
System info: ec2 instances running CoreOS 1.12 behind an ELB
Shutdown docker
Execute the results of the commands
reboot (easiest way to bring everything back up)
This recovered about 25% of the disk after the services restarted with no ill side affects.
docker ps
--quiet
--all
--filter status=exited
docker rm
docker images
docker rmi
Your hacky way is fine.
My hacky way is
A slightly cleaner way is to run
docker ps
with the--quiet
(-q) flag to get just the id number and--filter status=exited
to --filter just the exited ones.or to run
docker rm
with the--force
(-f) flag anddocker ps
with the--all
(-a) flag to shut down even the running onesWhat's probably taking up all that disk space after several failed builds is the images. To conserve disk space on the docker host, periodically remove unused docker images with
or to get more aggressive, you can
--force
(-f) it to clean up--all
(-a) images@analytik 's way of putting it into a .bashrc function seems like a practical idea
and if you're in the habit of generating lots of docker images that you don't need, add it to .bash_logout
I have added this to bashrc in my dev environment, and gotten used to running it every day or so.
In some cases, the following script can free up more space, as it will try to remove all images, and just fail silently:
Sadly, they're not significantly cleaner than your solution.
EDIT: Starting with Docker 1.13, you can use docker system:
EDIT: Starting with Docker 2017.09, you can also use container and image
the latter you can use with fancy filters like
--filter "until=24h"
here is resolution to clean docker overlay directory from https://lebkowski.name/docker-volumes/
for Docker < 1.9 :
Or for Docker >=1.9 :
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.
From our side we used:
Which save me 3Go !
We use also the famous commands :
We put that on cron to manage a little bit more efficently our disk space.
Cheers
Reference: https://forums.docker.com/t/some-way-to-clean-up-identify-contents-of-var-lib-docker-overlay/30604/4