cli: `docker system prune -af --volumes` does not completely clear out overlay2 folder
Description
We run a lot of docker containers in our CI/CD, the majority using the docker run --rm option if that matters. We also build a few images and perform a docker system prune -af --volumes each night. Every couple of months we end up with 0 bytes remaining disk space due to /var/lib/docker/overlay2 retaining data despite the nightly cleanup. The only way to recover the disk space without breaking docker that I could find so far is a complete reinstall.
For reference:
$ docker system prune --all --force --volumes
Total reclaimed space: 0B
$ docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker volume ls
DRIVER VOLUME NAME
# du -ch /var/lib/docker --max-depth=1
4.0K /var/lib/docker/runtimes
28K /var/lib/docker/volumes
67G /var/lib/docker/overlay2
4.0K /var/lib/docker/tmp
4.0K /var/lib/docker/swarm
11M /var/lib/docker/buildkit
4.0K /var/lib/docker/containers
106M /var/lib/docker/image
16K /var/lib/docker/plugins
68K /var/lib/docker/network
67G /var/lib/docker
67G total
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 62G 46G 13G 79% /
# ls -lh /var/lib/docker/overlay2/
total 5.6M
drwx--x--- 5 root root 4.0K Oct 19 16:24 0042cff5c2b1153d4e2cc8d1249433c3fdf40a9af374de7372e0bb487fa59a0e
drwx--x--- 4 root root 4.0K Oct 19 16:24 0042cff5c2b1153d4e2cc8d1249433c3fdf40a9af374de7372e0bb487fa59a0e-init
drwx--x--- 4 root root 4.0K Oct 31 09:03 00656fdea360c00da5d9549adcb5f968ab19280e6dde08892f6d26901ba84cca
drwx--x--- 4 root root 4.0K Oct 30 12:47 0081118c886142094d4bfdac3051331b04a5937bc0cd9db5f4d292a793d54a33
drwx--x--- 4 root root 4.0K Oct 19 14:41 0124757a1161c7b9bc1f4a725a5ef90c7d0b9598d31e53c8c59780fc686c2ca4
...
drwx--x--- 4 root root 4.0K Nov 7 08:47 x32c6n0iual0i5x438yhm91zc
drwx--x--- 4 root root 4.0K Nov 6 08:49 x9g9q67ib6r4pr799rkjcacir
drwx--x--- 4 root root 4.0K Nov 9 07:45 yo8bov1h8hqzcpt3ubdsj3de1
# ls -lh /var/lib/docker/overlay2/ | wc -l
1388
# apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
# rm -rf /var/lib/docker
# rm -rf /var/lib/containerd
# apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 62G 20G 40G 33% /
Reproduce
- Intensive use of
docker run --rm,docker rmianddocker buildover weeks - Run
docker system prune -af --volumesevery day overnight - Observe disk filling up over time
Expected behavior
After running docker system prune -af --volumes, all data from dangling images, completed containers etc should be removed
docker version
**Note:** Below o/p is collected _after_ a reinstall. The version running for the past months has been 24.0.6.
Client: Docker Engine - Community
Version: 24.0.7
API version: 1.43
Go version: go1.20.10
Git commit: afdd53b
Built: Thu Oct 26 09:08:01 2023
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.20.10
Git commit: 311b9ff
Built: Thu Oct 26 09:08:01 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.24
GitCommit: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
runc:
Version: 1.1.9
GitCommit: v1.1.9-0-gccaecfc
docker-init:
Version: 0.19.0
GitCommit: de40ad0
docker info
Client: Docker Engine - Community
Version: 24.0.7
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.11.2
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.21.0
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 24.0.7
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: 61f9fd88f79f081d64d6fa3bb1a0dc71ec870523
runc version: v1.1.9-0-gccaecfc
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
Kernel Version: 5.15.0-76-generic
Operating System: Ubuntu 20.04.6 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.58GiB
Name: ****
ID: 2c71d842-867e-40fa-af3e-a6210ada7edd
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Additional Info
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 16
- Comments: 38
I just ran into the same strange issue here with our docker swarm accumulating some orphaned overlay2 directories which the normal
docker system prune -afprocedures including the builder cleaned cannot resolve for some reasons. However, I just remembered that when this happened the first time I found and partly modified some bash script which can be used to prune/cleanup these orphaned overlay2 quite nicely. So, for anyone interested see here:https://gist.github.com/jens-maus/115ba5e6bf8c801dcbd861e20e658704
So, by simply running this script it will search for these orphaned overlay2 directories and then you can re-run it again by adding the
-noption to let it actually do the cleanup. Hope this helps some others running into the same issue over and over again until the docker developer can finally fix this issue so that the standard prune command can clean these orphaned overlay2 directories as well.Bump, why is
docker system prune -afanddoucker builder prune -afnot removing everything like it should. How can we set the cache expiration??? something???Hello? It’s been 5 months.
Is the solution to this really… Basically reinstall docker??? You expect me to
rm -rf /var/lib/dockerevery couple weeks or so???After removing all containers, and pruning, I still have 45gb in my overlay2. What gives? What’s happening? Why is it STILL happening?
@EyuelMathewos That seems to have done it! Docker recovered after the restart and is no longer generating the above error during builds 🥳
Does any of that help to narrow down why
docker system prune -afis not able to detect and remove all of the unused data? Ideally that should be the only command I need to run every now and then. For sure nuking the entire /var/lib/docker dir every time is a non-starter…You keep it running. In fact, it must run because this script executes docker queries to identify the orphaned overlay2 directories. And no, no explicit docker restart is required afterwards.
Hi @EyuelMathewos - Thanks for your suggestion. I had the same problems, which were solved using the command you provided.
While this solution works, periodically deleting the Docker folder isn’t a sustainable long-term approach, because it causes downtime for my GitLab runner container.
Are there any better methods or best practices to manage overlay2 disk usage without manual deletion?