Search code examples
dockerdocker-compose

Docker : Overlay2 size too big


I'm running docker's environment with two containers.I noted the overlay2 folder size is too big. When the docker is down (docker-compose down) the overlay2 folder is 2.3GB size. When the containers are running, the overlay2 folder increase to 4.0GB and it's increasing by the time. Is it normal?

The command du -shc /var/lib/docker/* with the containers stoped:

76K     /var/lib/docker/buildkit
268K    /var/lib/docker/containers
3.7M    /var/lib/docker/image
64K     /var/lib/docker/network
2.3G    /var/lib/docker/overlay2
0       /var/lib/docker/plugins
0       /var/lib/docker/runtimes
0       /var/lib/docker/swarm
0       /var/lib/docker/tmp
0       /var/lib/docker/tmp-old
0       /var/lib/docker/trust
236M    /var/lib/docker/volumes
2.5G    total

The command du -shc /var/lib/docker/* with the containers running:

76K     /var/lib/docker/buildkit
448K    /var/lib/docker/containers
4.9M    /var/lib/docker/image
64K     /var/lib/docker/network
4.0G    /var/lib/docker/overlay2
0       /var/lib/docker/plugins
0       /var/lib/docker/runtimes
0       /var/lib/docker/swarm
0       /var/lib/docker/tmp
0       /var/lib/docker/tmp-old
0       /var/lib/docker/trust
235M    /var/lib/docker/volumes
4.3G    total

EDIT

The command docker system df

TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          4         3         1.472GB   750.4MB (50%)
Containers      13        2         106.9MB   89.31MB (83%)
Local Volumes   62        1         1.884GB   1.817GB (96%)
Build Cache     0         0         0B        0B

Solution

  • First, run docker system df. It displays information regarding the amount of disk space used by the docker daemon. You can see here.

    Here is an example. You have 5 images, 2 actives and the local volume with one in inactive. So you can reclaim a free space. For each type you can reclaim a free space.

    1. image : you can remove images unused with the command line docker image rmi <image name>. More info here
    2. containers: you can remove an inactive containers with the command line docker container rm <container name>. More info here
    3. local volumes: you can reclaim a free space using the command line docker volume prune. More info here

    enter image description here

    After all these steps, you can check the Overlay2 consume. If it's ok or not: du -shc /var/lib/docker/* .

    enter image description here

    The garbage collection is a misterios in all tecnologias. You think it's work like this, but it works in other way around. You can learn more here.

    ATTENTION: Be careful using the docker system prune. Learn more here.