- 2023-08-01
- What happens is that sometimes the /var/lib/docker/overlay2 folder gets filled with subfolders and its size increase.
- No amount of `docker system prune -a -f` or 'docker image prune -a' or 'docker buildx prune -a' or similar command is able to clean up everything. A good chunk of subfolders stay there.
- So what to do?
- As of today, the overlay2 folder contains subfolders that represent container layers. If while building an image a middle step was creating data during the build process, that layer is saved and stored in the overlay2 folder.
- It would be like /var/lib/docker/overlay2/<some hash>/diff/<data here> .
- Now this should be deleted with image prune -a or the cache prune. But it is not, because somehow those folder gets orphaned.
- One approach is the following. (if one can delete everything)
- - Stop the docker service.
- - list the docker packages in the system, for example: yum list installed | grep -i docker
- - remove them (yum remove <packages>)
- - then move /var/lib/docker to /tmp
- - reinstall the packages
- - ensure that docker works
- - remove /tmp/docker
- If you cannot remove everything:
- - stop the docker service
- - Collect all the folder names that are hashes.
- - then you can try to delete the content saved by the container, removing entries in each /var/lib/docker/overlay2/<hash>/diff/<content that can be removed>
- - restart the docker service
- - do some tests, it should work.