Aswin George
Aswin George

Reputation: 147

Docker Cleanup - Can I delete old directories under /var/lib/docker/containers

I have 16 docker containers running in my system which stores a lot of data under/var/lib/docker/overlay2/<id>(around 30 GB per-directory.. Total 30*16 GB). Primarily space is consumed by diff and merged directories inside it.

Every time I do a docker-compose down followed by docker-compose up, it creates another set of 16 directories and starts storing data under that. But it does not clean up old overlay2 directories. This leads to a space crunch

  1. Please let me know if I can do rm -rf /var/lib/docker/overlay2/ of old directories or how I can free up space.
  2. Do I need to wait for a couple of hours after docker-compose down to reclaim space?

Note: I did a docker system prune -a also.

Upvotes: 3

Views: 5172

Answers (1)

davidxxx
davidxxx

Reputation: 131346

1)Please let me know if I can do rm -rf /var/lib/docker/overlay2/ of old directories or how I can free up space.

Only you can decide that.
When I suspect unused data for a /var/lib/docker/overlay2/foo123 folder, I first inspect the content of that folder. It contains generally image content. With modification date of files and content of files , I have a high probability to determinate if the folder is useless.
When I am sure that it is useless, I delete it with rm -rf .... Note that the delete may fail because file mounting, in that case I identify them and unmount them first.
If I am not sure that it is useless, I perform a backup before such as cp -a /var/lib/docker/overlay2/foo123 /var/lib/docker/overlay2/backup-foo123 before deleting

2)Do I need to wait for a couple of hours after docker-compose down to reclaim space?

With just Docker, no at all. Data have to be explicitly removed (such as : docker container rm FOO, docker system prune, docker system prune -a, docker image rm FOO and so for).
But Docker is not perfect. So sometimes you may have stale data.
Generally from time to time, I inspect docker big folders with a du -sh */ | sort -h.

Upvotes: 2

Related Questions