0

I have a concept to understand here to solve a problem I am facing with my docker containers and the disk usage by them.

When I dig into the overlay directory of a container, (for example in /var/lib/docker/overlay2/0ec5c07ba6ae1692ad127173/diff/home/bamboo/.m2/repository) I see a lot of files that are unnecessary consuming the disk space ~200G and I want to understand why these files are still here in this directory.

I am assuming that this has something to do with the docker top most writable layer concept to keep track of the changes. But I want to know if these files are supposed to be deleted by Docker at any point? If not, can we just delete them without impacting the containers?

I have already tried Docker prune command trying to delete these files with no luck!

I would appreciate it if someone could share some light on this to help me understand the concept and solve my problem.

Thanks in advance!

NewCoder
  • 23
  • 1
  • 6

1 Answers1

0

docker prune is for inactive containers only

docker prune clears only unused space. I.e. images, networks and volumes that are not used by active containers.

So, maybe some of active containers use OverlayFS layers with .m2 cache

.m2 is for cache

.m2 directory is intended to store Maven repository cache. See this answer for explanation. You can clean it using find tool

E.g.:

sudo find /var/lib/docker/overlay2 -name '.m2' -type d -exec rm -rf {}\repository \;
Yasen
  • 4,241
  • 1
  • 16
  • 25
  • Thanks for the answer! Is it also a good practice to mount the ".m2" directory to the host directory instead of it writing on the overlay directory? @Yasen – NewCoder Feb 05 '20 at 14:29
  • Hi. I'm not sure why are you need `.m2` in the docker context at all. Since containers recommended for non-persistent usage - why are you use maven inside docker? – Yasen Feb 05 '20 at 14:46
  • I am working with Bamboo, so the setup is like this: I have a Linux machine on top I have a container with the softwarre like Maven, ANT, etc. And inside the container, I have the Bamboo agent sitting on it which is used to make the builds. so Maven is used in this context. Is there any other efficient way of doing it? – NewCoder Feb 05 '20 at 15:03