amazon web services - how to clean up docker overlay directory? - Stack Overflow (https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a) (Stack Overflow) (https://stackoverflow.com/opensearch.xml) (https://stackoverflow.com/questions/31712266/how-to-clean-up-docker-overlay-directory) (Feed for question 'how to clean up docker overlay directory?') (https://stackoverflow.com/feeds/question/31712266) (site logo) Join Stack Overflow By clicking “Sign up”, you agree to our (https://stackoverflow.com/legal/terms-of-service/public) terms of service and acknowledge you have read our (https://stackoverflow.com/legal/privacy-policy) privacy policy . Sign up with Google Sign up with GitHub OR Email Password (8+ characters (at least 1 letter & 1 number)) Sign up Already have an account? (https://stackoverflow.com/users/login) Log in Skip to main content (https://stackoverflow.com/) Stack Overflow (https://stackoverflow.co/) About Products (https://stackoverflow.co/teams/) For Teams (Search…) (Click to show search) (https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f31712266%2fhow-to-clean-up-docker-overlay-directory) Log in (https://stackoverflow.com/users/signup?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f31712266%2fhow-to-clean-up-docker-overlay-directory) Sign up The 2025 Developer Survey results are in. Explore insights into technology and tools, careers, community and more. (https://survey.stackoverflow.co/2025?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=dev-survey-2025&utm_content=results-announcement-banner) View results . (dismiss) Let's set up your homepage Select a few topics you're interested in: python javascript c# reactjs java android html flutter c++ node.js typescript css r php angular next.js spring-boot machine-learning sql excel ios azure docker Or search from our full list: (Search) Next You’ll be prompted to create an account to view your personalized homepage. (https://stackoverflow.com/) Home (https://stackoverflow.com/questions) Questions (https://stackoverflow.ai/) AI Assist Labs (https://stackoverflow.com/tags) Tags (https://stackoverflow.com/beta/challenges) Challenges (https://chat.stackoverflow.com/rooms/259507/stack-overflow-lobby) Chat (https://stackoverflow.blog/contributed?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=so-blog&utm_content=experiment-articles) Articles (https://stackoverflow.com/users) Users (https://stackoverflow.com/jobs?source=so-left-nav) Jobs (https://stackoverflow.com/jobs/companies?so_medium=stackoverflow&so_source=SiteNav) Companies Collectives Communities for your favorite technologies. (https://stackoverflow.com/collectives-all) Explore all Collectives Teams Ask questions, find answers and collaborate at work with Stack Overflow for Teams. (https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) Try Teams for free (https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) Explore Teams (Illustration of upvote icon after it is clicked) Hang on, you can't upvote just yet. You'll need to complete a few actions and gain 15 reputation points before being able to upvote. Upvoting indicates when questions and answers are useful. (https://stackoverflow.com/help/whats-reputation) What's reputation and how do I get it? Instead, you can save this post to reference later. Save this post for later Not now (https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon.png?v=c78bd457575a) (https://stackoverflow.com/questions/31712266/how-to-clean-up-docker-overlay-directory) how to clean up docker overlay directory? (https://stackoverflow.com/questions/ask) Ask Question (2015-07-29 22:29:16Z) Asked 10 years ago Modified (https://stackoverflow.com/questions/31712266/how-to-clean-up-docker-overlay-directory?lastactivity) (2024-02-19 20:13:22Z) 1 year, 5 months ago (Viewed 227,406 times) Viewed 227k times Part of (https://stackoverflow.com/collectives/aws) AWS Collective This question shows research effort; it is useful and clear 126 (This question does not show any research effort; it is unclear or not useful) Save this question. (https://stackoverflow.com/posts/31712266/timeline) Show activity on this post. 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 (https://github.com/chadoe/docker-cleanup-volumes/) 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? (https://stackoverflow.com/collectives/aws) AWS Collective (https://stackoverflow.com/questions/tagged/amazon-web-services) (show questions tagged 'amazon-web-services') amazon-web-services (https://stackoverflow.com/questions/tagged/docker) (show questions tagged 'docker') docker (https://stackoverflow.com/questions/tagged/coreos) (show questions tagged 'coreos') coreos (https://stackoverflow.com/q/31712266) (Short permalink to this question) Share (https://stackoverflow.com/posts/31712266/edit) Improve this question Follow Follow this question to receive notifications asked (2015-07-29 22:29:16Z) Jul 29, 2015 at 22:29 (https://stackoverflow.com/users/659298/300d7309ef17) (300D7309EF17's user avatar) (https://stackoverflow.com/users/659298/300d7309ef17) 300D7309EF17 300D7309EF17 (reputation score 24,793) 24.8k (14 gold badges) 14 14 gold badges (90 silver badges) 90 90 silver badges (103 bronze badges) 103 103 bronze badges (Use comments to ask for more information or suggest improvements. Avoid answering questions in comments.) Add a comment | (Expand to show all comments on this post) 12 Answers 12 Sorted by: (https://stackoverflow.com/questions/31712266/how-to-clean-up-docker-overlay-directory?answertab=scoredesc#tab-top) Reset to default (scoredesc) Highest score (default) (trending) Trending (recent votes count more) (modifieddesc) Date modified (newest first) (createdasc) Date created (oldest first) This answer is useful 223 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/46159681/timeline) Show activity on this post. 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) https://forums.docker.com/t/some-way-to-clean-up-identify-contents-of-var-lib-docker-overlay/30604/4 Disclaimer Careful with that 3rd command (... xargs -r docker volume rm). Make sure the containers that may use those volumes are running when you run this. Otherwise, they will be seen as dangling, and therefore deleted. (https://stackoverflow.com/a/46159681) (Short permalink to this answer) Share (https://stackoverflow.com/posts/46159681/edit) Improve this answer Follow Follow this answer to receive notifications (https://stackoverflow.com/posts/46159681/revisions) (show all edits to this post) edited (2024-02-19 20:13:22Z) Feb 19, 2024 at 20:13 (https://stackoverflow.com/users/1907888/robert-sinclair) (Robert Sinclair's user avatar) (https://stackoverflow.com/users/1907888/robert-sinclair) Robert Sinclair (reputation score) 5,486 (2 gold badges) 2 2 gold badges (49 silver badges) 49 49 silver badges (52 bronze badges) 52 52 bronze badges answered (2017-09-11 15:51:43Z) Sep 11, 2017 at 15:51 (https://stackoverflow.com/users/3774109/user3774109) (user3774109's user avatar) (https://stackoverflow.com/users/3774109/user3774109) user3774109 user3774109 (reputation score) 2,496 (1 gold badge) 1 1 gold badge (14 silver badges) 14 14 silver badges (13 bronze badges) 13 13 bronze badges 4 (number of 'useful comment' votes received) 5 Life saver! I had no idea why df said my ec2 volume was full until I ran ncdu on my /var directory which led me here! I reclaimed 280+ GB from that first command! – (https://stackoverflow.com/users/6032583/josh-yolles) (108 reputation) Josh Yolles Commented (2020-09-22 18:22:47Z, License: CC BY-SA 4.0) Sep 22, 2020 at 18:22 (number of 'useful comment' votes received) 4 Careful with that 3rd command (... xargs -r docker volume rm ). Make sure the containers that may use those volumes are running when you run this. Otherwise, they will be seen as dangling, and therefore deleted. – (https://stackoverflow.com/users/242404/julien) (1,037 reputation) Julien Commented (2020-10-07 23:29:30Z, License: CC BY-SA 4.0) Oct 7, 2020 at 23:29 (this comment was edited 2 times) (number of 'useful comment' votes received) 1 There is a lot of discussion on this: (https://github.com/moby/moby/issues/33775) github.com/moby/moby/issues/33775 A lot of people have run into the overlay directory consuming more space than expected and that it isn't clear how to clean it up. – (https://stackoverflow.com/users/5114/mnebuerquo) (5,999 reputation) Mnebuerquo Commented (2022-04-22 20:33:13Z, License: CC BY-SA 4.0) Apr 22, 2022 at 20:33 (number of 'useful comment' votes received) 1 Please pay attention, the command docker system prune -a -f will remove any stopped container. If you have a container stopped for a moment and you plan to use it in the future, do not use -a option. – (https://stackoverflow.com/users/4511648/dorin) (1,096 reputation) Dorin Commented (2024-01-18 13:48:16Z, License: CC BY-SA 4.0) Jan 18, 2024 at 13:48 (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 21 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/76117532/timeline) Show activity on this post. docker builder prune this helps cleaning up the docker overlay2 folder (https://stackoverflow.com/a/76117532) (Short permalink to this answer) Share (https://stackoverflow.com/posts/76117532/edit) Improve this answer Follow Follow this answer to receive notifications answered (2023-04-27 06:54:15Z) Apr 27, 2023 at 6:54 (https://stackoverflow.com/users/20830490/tomitomsen3000) (tomitomsen3000's user avatar) (https://stackoverflow.com/users/20830490/tomitomsen3000) tomitomsen3000 tomitomsen3000 (reputation score) 211 (2 silver badges) 2 2 silver badges (3 bronze badges) 3 3 bronze badges 2 (number of 'useful comment' votes received) 1 Just cleared 50GB with this. Apparently the build layers are also cached in here, so its not only used by running containers. – (https://stackoverflow.com/users/2545722/afp-555) (2,638 reputation) AFP_555 Commented (2023-10-04 15:35:28Z, License: CC BY-SA 4.0) Oct 4, 2023 at 15:35 (number of 'useful comment' votes received) 1 THIS!! Thank you. I cleared 330GB with this. My overlay2 directory had grown to 400+GB. I always do a image or system prune, but I was never able to really clean up the hundreds of GB. In the past I would shutdown docker service, rm -rf the overlay directory, then restart docker. But now I don't have to lose everything to clean up space. – (https://stackoverflow.com/users/5893484/cristhian-ulloa) (81 reputation) Cristhian Ulloa Commented (2024-10-17 14:02:13Z, License: CC BY-SA 4.0) Oct 17, 2024 at 14:02 (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 15 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/31889317/timeline) Show activity on this post. 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` (https://stackoverflow.com/a/31889317) (Short permalink to this answer) Share (https://stackoverflow.com/posts/31889317/edit) Improve this answer Follow Follow this answer to receive notifications answered (2015-08-08 03:26:08Z) Aug 8, 2015 at 3:26 (https://stackoverflow.com/users/659298/300d7309ef17) (300D7309EF17's user avatar) (https://stackoverflow.com/users/659298/300d7309ef17) 300D7309EF17 300D7309EF17 (reputation score 24,793) 24.8k (14 gold badges) 14 14 gold badges (90 silver badges) 90 90 silver badges (103 bronze badges) 103 103 bronze badges 1 (number of 'useful comment' votes received) 2 awk can filter: docker ps -a | awk '/Exited/{ print $1 }' . Nice hack though. – (https://stackoverflow.com/users/1598508/krzysztof-jab%c5%82o%c5%84ski) (1,941 reputation) Krzysztof Jabłoński Commented (2018-02-26 15:42:26Z, License: CC BY-SA 3.0) Feb 26, 2018 at 15:42 (this comment was edited 2 times) (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 14 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/32564760/timeline) Show activity on this post. I have added this to bashrc in my dev environment, and gotten used to running it every day or so. function cleanup_docker() { docker ps -f status=exited -q | xargs -r docker rm docker images -f dangling=true -q | xargs -r docker rmi } In some cases, the following script can free up more space, as it will try to remove all images, and just fail silently: function cleanup_docker_aggressive() { for i in $(docker images --no-trunc -q | sort -u) do docker rmi $i 2> /dev/null done } Sadly, they're not significantly cleaner than your solution. EDIT: Starting with Docker 1.13, you can use (https://docs.docker.com/v1.13/engine/reference/commandline/system/) docker system : docker system df # to check what is using space docker system prune # cleans up also networks, build cache, etc EDIT: Starting with Docker 2017.09, you can also use (https://docs.docker.com/engine/reference/commandline/container_prune/) container and (https://docs.docker.com/engine/reference/commandline/image_prune/) image docker container prune docker image prune -a the latter you can use with fancy filters like --filter "until=24h" (https://stackoverflow.com/a/32564760) (Short permalink to this answer) Share (https://stackoverflow.com/posts/32564760/edit) Improve this answer Follow Follow this answer to receive notifications (https://stackoverflow.com/posts/32564760/revisions) (show all edits to this post) edited (2018-11-20 07:56:51Z) Nov 20, 2018 at 7:56 answered (2015-09-14 12:24:35Z) Sep 14, 2015 at 12:24 (https://stackoverflow.com/users/2277364/analytik) (analytik's user avatar) (https://stackoverflow.com/users/2277364/analytik) analytik analytik (reputation score) 792 (7 silver badges) 7 7 silver badges (16 bronze badges) 16 16 bronze badges 3 (number of 'useful comment' votes received) 1 I've cleaned everything but overlay directory is still 20GB+ while active containers+images use only 6GB together – (https://stackoverflow.com/users/1713660/vladkras) (17,235 reputation) vladkras Commented (2017-09-04 13:04:48Z, License: CC BY-SA 3.0) Sep 4, 2017 at 13:04 (this comment was edited 2 times) (number of 'useful comment' votes received) 1 @vladkras - If you can, try restarting the docker containers one by one (not just halt+resume) and then run the cleanup again. Likely there's something producing a lot of logs. If that doesn't help, maybe you're not counting the supposed usage correctly? Also, I highly recommend switching to overlay2, unless some service is producing a ton of log output, you should save 60%+ of space. – (https://stackoverflow.com/users/2277364/analytik) (792 reputation) analytik Commented (2017-09-04 16:34:39Z, License: CC BY-SA 3.0) Sep 4, 2017 at 16:34 save me a half of my sda, docker version ─╯ Client: Version: 18.09.6 API version: 1.39 Go version: go1.10.8 – (https://stackoverflow.com/users/1426388/tiana987642) (754 reputation) Tiana987642 Commented (2023-03-01 20:04:16Z, License: CC BY-SA 4.0) Mar 1, 2023 at 20:04 (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 11 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/73172422/timeline) Show activity on this post. It's not real! /var/lib/docker/overlay2 , as the name suggests, contains a bunch of overlay file systems (good intro (https://wiki.archlinux.org/title/Overlay_filesystem) here ). Run mount | grep overlay2 and you will see that all the /var/lib/docker/overlay2/*/merged folders are of mounts of type overlay . This means that what du says isn't real . To get a sense of how much space is actually being used in those folders (on disk) you need to limit your attention to just the upper directory of the overlayfs mount (called diff in docker's case), e.g.: du -sch /var/lib/docker/overlay2/*/diff ... 3.8G total for comparison, in my case: > du -sch /var/lib/docker/overlay2 ... 17G total Update It seems that you can also simply use du 's -x /--one-file-system option ("skip directories on different file systems") to only see the real part: > du -schx /var/lib/docker/overlay2 (https://stackoverflow.com/a/73172422) (Short permalink to this answer) Share (https://stackoverflow.com/posts/73172422/edit) Improve this answer Follow Follow this answer to receive notifications (https://stackoverflow.com/posts/73172422/revisions) (show all edits to this post) edited (2023-10-18 00:20:29Z) Oct 18, 2023 at 0:20 answered (2022-07-30 02:15:42Z) Jul 30, 2022 at 2:15 (https://stackoverflow.com/users/1087119/christian-fritz) (Christian Fritz's user avatar) (https://stackoverflow.com/users/1087119/christian-fritz) Christian Fritz Christian Fritz (reputation score 21,464) 21.5k (3 gold badges) 3 3 gold badges (48 silver badges) 48 48 silver badges (82 bronze badges) 82 82 bronze badges 3 So if 'du' say all space is used on the disk, and it's being used by the overlay, how does saying its not real help? My disk writes are now failing...so it's real enough to interfere with operations. Is the a command to align real with reported disk usage? – (https://stackoverflow.com/users/659503/tsg) (4,716 reputation) TSG Commented (2023-10-17 20:56:21Z, License: CC BY-SA 4.0) Oct 17, 2023 at 20:56 du doesn't tell you anything about the disk being full or not. Do you perhaps mean df ? If so, what df says is always real. And I believe your question is answered by my answer, which tells you how to only see the real part. – (https://stackoverflow.com/users/1087119/christian-fritz) (21,464 reputation) Christian Fritz Commented (2023-10-18 00:17:24Z, License: CC BY-SA 4.0) Oct 18, 2023 at 0:17 I meant 'df' sorry – (https://stackoverflow.com/users/659503/tsg) (4,716 reputation) TSG Commented (2023-10-18 01:29:02Z, License: CC BY-SA 4.0) Oct 18, 2023 at 1:29 (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 10 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/44293999/timeline) Show activity on this post. 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 Drain the docker instance from the ELB Shutdown docker systemctl stop docker rm -rf /var/lib/docker/overlay/* Execute the results of the commands for d in $(find /var/lib/docker/image/overlay -type d -name '*sha256*'); do echo rm -rf $d/* ; done reboot (easiest way to bring everything back up) This recovered about 25% of the disk after the services restarted with no ill side affects. (https://stackoverflow.com/a/44293999) (Short permalink to this answer) Share (https://stackoverflow.com/posts/44293999/edit) Improve this answer Follow Follow this answer to receive notifications answered (2017-05-31 20:20:52Z) May 31, 2017 at 20:20 (https://stackoverflow.com/users/144594/kevin-mcfadden) (Kevin McFadden's user avatar) (https://stackoverflow.com/users/144594/kevin-mcfadden) Kevin McFadden Kevin McFadden (reputation score) 139 (1 silver badge) 1 1 silver badge (4 bronze badges) 4 4 bronze badges 3 tried your cleanup and ended having all service creation rejected after with error message lstat /var/lib/docker/overlay – (https://stackoverflow.com/users/1762447/tkyass) (3,206 reputation) tkyass Commented (2017-06-15 22:14:07Z, License: CC BY-SA 3.0) Jun 15, 2017 at 22:14 (number of 'useful comment' votes received) 1 did you remove the overlay directory by accident? lstat is for symlnks, but mine isn't a symlink. – (https://stackoverflow.com/users/144594/kevin-mcfadden) (139 reputation) Kevin McFadden Commented (2017-06-17 01:59:00Z, License: CC BY-SA 3.0) Jun 17, 2017 at 1:59 (this comment was edited 1 time) Even after stopping docker I still had some locked folders in /var/lib/docker/overlay/ . I had to manually umount them so that I could delete them. – (https://stackoverflow.com/users/316857/joel-b) (13,270 reputation) Joel B Commented (2017-06-26 01:57:53Z, License: CC BY-SA 3.0) Jun 26, 2017 at 1:57 (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 7 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/34094620/timeline) Show activity on this post. docker ps --quiet --all --filter status=exited docker rm --force docker images --quiet --all --filter dangling=true docker rmi -- force Your hacky way is fine. docker rm `docker ps -a | grep Exited | awk '{print $1 }'` My hacky way is docker rm $(docker ps --all | awk '/ago/{print $1}') 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. docker rm $(docker ps --filter status=exited --quiet) # remove stopped docker processes or to run docker rm with the --force (-f) flag and docker ps with the --all (-a) flag to shut down even the running ones docker rm --force $(docker ps --all --quiet) # remove all docker processes What'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 docker rmi $(docker images --filter dangling=true --quiet) # clean dangling docker images or to get more aggressive, you can --force (-f) it to clean up --all (-a) images docker rmi --force $(docker images --all --quiet) # clean all possible docker images @analytik 's way of putting it into a (http://www.cyberciti.biz/faq/ubuntu-linux-user-profile-bash-configuration/) .bashrc function seems like a practical idea function cleanup_docker() { docker rm --force $(docker ps --all --quiet) # remove all docker processes docker rmi $(docker images --filter dangling=true --quiet) # clean dangling docker images } and if you're in the habit of generating lots of docker images that you don't need, add it to (http://www.cyberciti.biz/faq/linux-unix-run-commands-when-you-log-out/) .bash_logout (https://stackoverflow.com/a/34094620) (Short permalink to this answer) Share (https://stackoverflow.com/posts/34094620/edit) Improve this answer Follow Follow this answer to receive notifications answered (2015-12-04 18:03:19Z) Dec 4, 2015 at 18:03 (https://stackoverflow.com/users/1261193/woodvi) (woodvi's user avatar) (https://stackoverflow.com/users/1261193/woodvi) woodvi woodvi (reputation score) 2,026 (24 silver badges) 24 24 silver badges (27 bronze badges) 27 27 bronze badges (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 3 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/72066509/timeline) Show activity on this post. Please be aware that docker prune commands do not clean /var/lib/docker/overlay2 directory. It is also not advised to remove only the overlay directory as it may impact existing containers. I have searched for a lot of articles but couldn't find any solution to clean overlay directory other than cleaning the entire docker state: # Please understand that this will restart the docker engine in a completely empty state # i.e. you will lose all images, containers, volumes, networks, swarm state, etc. # You can obviously first take the backup of the directories that you want to keep and copy the contents back after restarting docker service. service stop docker rm -rf /var/lib/docker service start docker The last command brings the docker service back up with all the folders inside /var/lib/docker again. (https://stackoverflow.com/a/72066509) (Short permalink to this answer) Share (https://stackoverflow.com/posts/72066509/edit) Improve this answer Follow Follow this answer to receive notifications answered (2022-04-30 07:24:13Z) Apr 30, 2022 at 7:24 (https://stackoverflow.com/users/13587704/rahul-kumar) (Rahul Kumar's user avatar) (https://stackoverflow.com/users/13587704/rahul-kumar) Rahul Kumar Rahul Kumar (reputation score) 849 (8 silver badges) 8 8 silver badges (8 bronze badges) 8 8 bronze badges (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 2 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/61937329/timeline) Show activity on this post. I followed these simple steps Step 1: df -h [checked the memory used, to be sure, memory is used by overlay folder]. Step 2: sudo docker system prune [this cmd removes all unused containers/images/networks] Step 3: sudo docker image prune -a [for any dangling images, if present] Step 4: df -h [to be sure, overlay data is removed]. (https://stackoverflow.com/a/61937329) (Short permalink to this answer) Share (https://stackoverflow.com/posts/61937329/edit) Improve this answer Follow Follow this answer to receive notifications answered (2020-05-21 14:55:12Z) May 21, 2020 at 14:55 (https://stackoverflow.com/users/3656625/aniket-j-kamble) (Aniket J kamble's user avatar) (https://stackoverflow.com/users/3656625/aniket-j-kamble) Aniket J kamble Aniket J kamble (reputation score) 140 (1 silver badge) 1 1 silver badge (8 bronze badges) 8 8 bronze badges (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 1 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/39803910/timeline) Show activity on this post. Docker garbage collection can be done in an easy way using another docker container (https://github.com/spotify/docker-gc) https://github.com/spotify/docker-gc You could make it run as a cron using (https://github.com/flaccid/docker-docker-gc-crond) https://github.com/flaccid/docker-docker-gc-crond (https://stackoverflow.com/a/39803910) (Short permalink to this answer) Share (https://stackoverflow.com/posts/39803910/edit) Improve this answer Follow Follow this answer to receive notifications answered (2016-10-01 07:04:49Z) Oct 1, 2016 at 7:04 (https://stackoverflow.com/users/2487549/foreever) (Foreever's user avatar) (https://stackoverflow.com/users/2487549/foreever) Foreever Foreever (reputation score) 7,537 (10 gold badges) 10 10 gold badges (56 silver badges) 56 56 silver badges (59 bronze badges) 59 59 bronze badges (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 1 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/60344217/timeline) Show activity on this post. Here is a working option: docker rm -f $(docker ps -a |awk 'NR>1&&/Exited/{print $1}') (https://stackoverflow.com/a/60344217) (Short permalink to this answer) Share (https://stackoverflow.com/posts/60344217/edit) Improve this answer Follow Follow this answer to receive notifications answered (2020-02-21 18:14:26Z) Feb 21, 2020 at 18:14 (https://stackoverflow.com/users/6266192/dudi-boy) (Dudi Boy's user avatar) (https://stackoverflow.com/users/6266192/dudi-boy) Dudi Boy Dudi Boy (reputation score) 1 (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) This answer is useful 0 (This answer is not useful) Save this answer. (Loading when this answer was accepted…) (https://stackoverflow.com/posts/50255357/timeline) Show activity on this post. here is resolution to clean docker overlay directory from (https://lebkowski.name/docker-volumes/) https://lebkowski.name/docker-volumes/ docker images --no-trunc | grep '' | awk '{ print $3 }' | xargs -r docker rmi docker ps --filter status=dead --filter status=exited -aq | xargs docker rm -v for Docker < 1.9 : find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(docker ps -aq | xargs docker inspect | jq -r '.[]|.Mounts|.[]|.Name|select(.)') Or for Docker >=1.9 : docker volume ls -qf dangling=true | xargs -r docker volume rm (https://stackoverflow.com/a/50255357) (Short permalink to this answer) Share (https://stackoverflow.com/posts/50255357/edit) Improve this answer Follow Follow this answer to receive notifications answered (2018-05-09 14:01:43Z) May 9, 2018 at 14:01 (https://stackoverflow.com/users/9764918/wolvverine) (Wolvverine's user avatar) (https://stackoverflow.com/users/9764918/wolvverine) Wolvverine Wolvverine (reputation score) 49 (4 bronze badges) 4 4 bronze badges (Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”.) Add a comment | (Expand to show all comments on this post) Your Answer Draft saved Draft discarded Sign up or (https://stackoverflow.com/users/login?ssrc=question_page&returnurl=https%3a%2f%2fstackoverflow.com%2fquestions%2f31712266%2fhow-to-clean-up-docker-overlay-directory%23new-answer) log in Sign up using Google Sign up using Email and Password Submit Post as a guest Name Email Required, but never shown Post as a guest Name () () Email Required, but never shown () () Post Your Answer Discard By clicking “Post Your Answer”, you agree to our (https://stackoverflow.com/legal/terms-of-service/public) terms of service and acknowledge you have read our (https://stackoverflow.com/legal/privacy-policy) privacy policy . Start asking to get answers Find the answer to your question by asking. (https://stackoverflow.com/questions/ask) Ask question Explore related questions (https://stackoverflow.com/questions/tagged/amazon-web-services) (show questions tagged 'amazon-web-services') amazon-web-services (https://stackoverflow.com/questions/tagged/docker) (show questions tagged 'docker') docker (https://stackoverflow.com/questions/tagged/coreos) (show questions tagged 'coreos') coreos See similar questions with these tags. (https://stackoverflow.com/collectives/aws) AWS Collective See more (https://stackoverflow.com/collectives) This question is in a collective: a subcommunity defined by tags with relevant content and experts. The Overflow Blog (https://stackoverflow.blog/2025/08/07/a-new-worst-coder-has-entered-the-chat-vibe-coding-without-code-knowledge/?cb=1) A new worst coder has entered the chat: vibe coding without code knowledge (https://stackoverflow.blog/2025/08/08/python-come-for-the-language-stay-for-the-community/?cb=1) Python: Come for the language, stay for the community Featured on Meta (Meta Stack Exchange) (https://meta.stackexchange.com/questions/411312/will-you-help-build-our-new-visual-identity?cb=1) Will you help build our new visual identity? (Meta Stack Exchange) (https://meta.stackexchange.com/questions/411578/upcoming-initiatives-on-stack-overflow-and-across-the-stack-exchange-network-j?cb=1) (Upcoming initiatives on Stack Overflow and across the Stack Exchange network - July 2025) Upcoming initiatives on Stack Overflow and across the Stack Exchange network... (Meta Stack Overflow) (https://meta.stackoverflow.com/questions/434624/further-experimentation-with-comment-reputation-requirements?cb=1) Further Experimentation with Comment Reputation Requirements (Meta Stack Overflow) (https://meta.stackoverflow.com/questions/434644/updated-design-for-the-new-live-activity-panel-experiment?cb=1) Updated design for the new live activity panel experiment Community activity Last 1 hr Users online activity 3984 users online Number of questions asked 6 questions Number of questions that received an answer 9 answers Number of comments posted 22 comments Number of upvotes on posts 71 upvotes Popular tags Popular tags (https://stackoverflow.com/questions/tagged/orientation) orientation (https://stackoverflow.com/questions/tagged/c#) c# (https://stackoverflow.com/questions/tagged/python) python (https://stackoverflow.com/questions/tagged/javascript) javascript (https://stackoverflow.com/questions/tagged/powershell) powershell (https://stackoverflow.com/questions/tagged/android) android Popular unanswered question Popular unanswered question (https://stackoverflow.com/questions/79715940) Angular 20 and fetching files in unit tests (https://stackoverflow.com/questions/tagged/angular) angular (https://stackoverflow.com/questions/tagged/unit-testing) unit-testing (https://stackoverflow.com/questions/tagged/karma-jasmine) karma-jasmine (https://stackoverflow.com/questions/tagged/karma-runner) karma-runner (https://stackoverflow.com/users/79677) (User avatar) (https://stackoverflow.com/users/79677) Chris Barr 34.5k (Saturday, July 26, 2025 at 7:13:22 PM UTC) 13 days ago Linked (https://stackoverflow.com/questions/54436314/docker-container-took-too-many-storage-of-disk?lq=1) (Question score (upvotes - downvotes)) 0 (https://stackoverflow.com/questions/54436314/docker-container-took-too-many-storage-of-disk?noredirect=1&lq=1) Docker container took too many storage of disk (https://stackoverflow.com/questions/63058210/gitlab-runner-cannot-reclaim-docker-space-on-ubuntu-no-space-left-on-device?lq=1) (Question score (upvotes - downvotes)) 1 (https://stackoverflow.com/questions/63058210/gitlab-runner-cannot-reclaim-docker-space-on-ubuntu-no-space-left-on-device?noredirect=1&lq=1) Gitlab runner: cannot reclaim Docker space on Ubuntu - no space left on device Related (https://stackoverflow.com/questions/23188932/how-do-i-clean-up-my-docker-host-machine?rq=3) (Question score (upvotes - downvotes)) 30 (https://stackoverflow.com/questions/23188932/how-do-i-clean-up-my-docker-host-machine?rq=3) how do I clean up my docker host machine (https://stackoverflow.com/questions/45798076/how-to-clean-up-docker?rq=3) (Question score (upvotes - downvotes)) 90 (https://stackoverflow.com/questions/45798076/how-to-clean-up-docker?rq=3) How to clean up Docker (https://stackoverflow.com/questions/46672001/is-it-safe-to-clean-docker-overlay2?rq=3) (Question score (upvotes - downvotes)) 481 (https://stackoverflow.com/questions/46672001/is-it-safe-to-clean-docker-overlay2?rq=3) Is it safe to clean docker/overlay2/ (https://stackoverflow.com/questions/48869913/docker-ce-overlay2?rq=3) (Question score (upvotes - downvotes)) 5 (https://stackoverflow.com/questions/48869913/docker-ce-overlay2?rq=3) Docker CE Overlay2 (https://stackoverflow.com/questions/50653502/cannot-run-or-delete-images-or-container-fail-overlay2?rq=3) (Question score (upvotes - downvotes)) 10 (https://stackoverflow.com/questions/50653502/cannot-run-or-delete-images-or-container-fail-overlay2?rq=3) Cannot run or delete images or container (fail overlay2) (https://stackoverflow.com/questions/54288260/clean-up-delete-all-the-docker-images-except-the-one-in-use?rq=3) (Question score (upvotes - downvotes)) 5 (https://stackoverflow.com/questions/54288260/clean-up-delete-all-the-docker-images-except-the-one-in-use?rq=3) Clean up . delete all the docker images except the one in use (https://stackoverflow.com/questions/61592088/why-is-docker-filling-up-var-lib-docker-overlay2?rq=3) (Question score (upvotes - downvotes)) 64 (https://stackoverflow.com/questions/61592088/why-is-docker-filling-up-var-lib-docker-overlay2?rq=3) Why is Docker filling up /var/lib/docker/overlay2? (https://stackoverflow.com/questions/61884165/docker-overlay2-eating-disk-space?rq=3) (Question score (upvotes - downvotes)) 21 (https://stackoverflow.com/questions/61884165/docker-overlay2-eating-disk-space?rq=3) Docker overlay2 eating Disk Space (https://stackoverflow.com/questions/65655199/how-to-fix-docker-container-after-deleting-overlay2-folder?rq=3) (Question score (upvotes - downvotes)) 13 (https://stackoverflow.com/questions/65655199/how-to-fix-docker-container-after-deleting-overlay2-folder?rq=3) How to fix docker container after deleting overlay2 folder (https://stackoverflow.com/questions/70606161/docker-overlay2-folder-eating-disk?rq=3) (Question score (upvotes - downvotes)) 5 (https://stackoverflow.com/questions/70606161/docker-overlay2-folder-eating-disk?rq=3) Docker overlay2 folder eating Disk (https://stackexchange.com/questions?tab=hot) Hot Network Questions (Philosophy Stack Exchange) (https://philosophy.stackexchange.com/questions/129352/the-unreasonable-effectiveness-of-digital-representation) The Unreasonable Effectiveness of Digital Representation (English Language & Usage Stack Exchange) (https://english.stackexchange.com/questions/632653/what-do-you-call-a-gift-mug-not-really-suitable-for-coffee) What do you call a gift mug not really suitable for coffee? (Physics Stack Exchange) (https://physics.stackexchange.com/questions/857105/am-i-getting-closer-to-the-car-in-front-if-they-are-moving-at-a-faster-velocity) Am I getting closer to the car in front if they are moving at a faster velocity but decelerating faster than me? (Arqade) (https://gaming.stackexchange.com/questions/413025/what-was-the-first-video-game-where-cold-slowed-enemies-down) What was the first video game where cold slowed enemies down? (Retrocomputing Stack Exchange) (https://retrocomputing.stackexchange.com/questions/31970/how-to-remove-end-of-snapped-zx-spectrum-keyboard-connector) How to remove end of snapped ZX Spectrum keyboard connector (Vi and Vim Stack Exchange) (https://vi.stackexchange.com/questions/47031/how-to-select-the-first-words-of-a-multiline-selection) How to select the first words of a multiline selection? (Geographic Information Systems Stack Exchange) (https://gis.stackexchange.com/questions/494897/exporting-to-file-geodatabase-results-in-odd-meaningless-popup-in-qgis) Exporting to File Geodatabase results in odd, meaningless popup in QGIS (Electrical Engineering Stack Exchange) (https://electronics.stackexchange.com/questions/753422/finding-the-current-of-the-leftmost-voltage-source-using-mesh-analysis) Finding the current of the leftmost voltage source using mesh analysis (Cross Validated) (https://stats.stackexchange.com/questions/669352/can-bootstrap-confidence-intervals-be-illogical) Can bootstrap confidence intervals be illogical? (Role-playing Games Stack Exchange) (https://rpg.stackexchange.com/questions/216257/generating-magic-weapons-how-many-roll-agains) Generating Magic Weapons - how many 'roll agains'? (Biblical Hermeneutics Stack Exchange) (https://hermeneutics.stackexchange.com/questions/107380/acts-1028-common-or-unclean-what-meaning-is-given-by-peter-in-this-statem) Acts 10:28 - "common or unclean" - What meaning is given by Peter in this statement to the ordinary word κοινὸν? (Bricks) (https://bricks.stackexchange.com/questions/19198/sets-that-can-make-lego-mario-play-a-tune) Sets that can make LEGO Mario play a tune (TeX - LaTeX Stack Exchange) (https://tex.stackexchange.com/questions/749445/how-to-put-a-tikz-image-and-an-algorithm-besides-each-other) How to put a tikz image and an algorithm besides each other? (Database Administrators Stack Exchange) (https://dba.stackexchange.com/questions/347438/on-sql-2022-declare-statement-causes-evaluation-of-database-availability) On SQL 2022, DECLARE statement causes evaluation of database availability (Electrical Engineering Stack Exchange) (https://electronics.stackexchange.com/questions/753410/fet-switch-not-shutting-off) FET Switch Not Shutting Off (History of Science and Mathematics Stack Exchange) (https://hsm.stackexchange.com/questions/18771/question-on-the-origin-of-an-einstein-quote) Question on the origin of an Einstein quote (Esperanto Language Stack Exchange) (https://esperanto.stackexchange.com/questions/6882/translating-the-programming-language-keyword-so-for-boolean-coercion) Translating the programming language keyword "so", for boolean coercion (Mathematics Stack Exchange) (https://math.stackexchange.com/questions/5088754/does-the-norm-decreases-along-the-limit-on-compactly-embedded-banach-subspace) Does the norm decreases, along the limit on compactly embedded Banach subspace? (TeX - LaTeX Stack Exchange) (https://tex.stackexchange.com/questions/749426/loops-in-tikz-with-extra-counter) Loops in tikz with extra counter (Super User) (https://superuser.com/questions/1916212/how-to-refer-to-the-output-of-a-command-as-an-argument-in-the-next-command-in-ba) How to refer to the output of a command as an argument in the next command in Bash shell? (Unix & Linux Stack Exchange) (https://unix.stackexchange.com/questions/798613/creating-n-folders-with-equal-number-of-files-from-a-large-folder-with-all-files) Creating n folders with equal number of files from a large folder with all files (Biblical Hermeneutics Stack Exchange) (https://hermeneutics.stackexchange.com/questions/107365/what-prompted-a-nobleman-in-capernaum-to-ask-jesus-to-heal-his-son) What prompted a nobleman in Capernaum to ask Jesus to heal his son? (Arqade) (https://gaming.stackexchange.com/questions/413040/what-was-the-first-jrpg-game-that-featured-custom-automatic-actions-triggered) What was the first JRPG game that featured custom automatic action(s) triggered by specific events? (Astronomy Stack Exchange) (https://astronomy.stackexchange.com/questions/61526/are-some-meteors-pieces-of-satellites) Are some meteors pieces of satellites? (https://stackoverflow.com/feeds/question/31712266) (Feed of this question and its answers) Question feed Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. (https://stackoverflow.com/feeds/question/31712266) () Why are you flagging this comment? (20) It contains harassment, bigotry or abuse. This comment attacks a person or group. Learn more in our (https://stackoverflow.com/conduct/abusive-behavior) Code of Conduct . (40) It's unfriendly or unkind. This comment is rude or condescending. Learn more in our (https://stackoverflow.com/conduct/abusive-behavior) Code of Conduct . (39) Not needed. This comment is not relevant to the post. (19) Something else. A problem not listed above. Try to be as specific as possible. Flag comment Cancel You have 0 flags left today (https://stackoverflow.com/) (https://stackoverflow.com/) Stack Overflow (https://stackoverflow.com/questions) Questions (https://stackoverflow.com/help) Help (https://chat.stackoverflow.com/?tab=explore) Chat (https://stackoverflow.co/) Products (https://stackoverflow.co/teams/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=teams) Teams (https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=advertising) Advertising (https://stackoverflow.co/advertising/employer-branding/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=talent) Talent (https://stackoverflow.co/) Company (https://stackoverflow.co/) About (https://stackoverflow.co/company/press/) Press (https://stackoverflow.co/company/work-here/) Work Here (https://stackoverflow.com/legal) Legal (https://stackoverflow.com/legal/privacy-policy) Privacy Policy (https://stackoverflow.com/legal/terms-of-service/public) Terms of Service (https://stackoverflow.com/contact) Contact Us Your Privacy Choices (https://policies.stackoverflow.co/stack-overflow/cookie-policy) Cookie Policy (https://stackexchange.com/) Stack Exchange Network (https://stackexchange.com/sites#technology) Technology (https://stackexchange.com/sites#culturerecreation) Culture & recreation (https://stackexchange.com/sites#lifearts) Life & arts (https://stackexchange.com/sites#science) Science (https://stackexchange.com/sites#professional) Professional (https://stackexchange.com/sites#business) Business (https://api.stackexchange.com/) API (https://data.stackexchange.com/) Data (https://stackoverflow.blog/?blb=1) Blog (https://www.facebook.com/officialstackoverflow/) Facebook (https://twitter.com/stackoverflow) Twitter (https://linkedin.com/company/stack-overflow) LinkedIn (https://www.instagram.com/thestackoverflow) Instagram Site design / logo © 2025 Stack Exchange Inc; user contributions licensed under (https://stackoverflow.com/help/licensing) CC BY-SA . rev 2025.8.6.32596 By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our (https://stackoverflow.com/legal/cookie-policy) Cookie Policy . Accept all cookies Necessary cookies only Customize settings