gogoWebsite

Docker overlay2 takes up a lot of disk space processing method

Updated to 19 hours ago

When using docker, there is often insufficient disk space, and the usual reason for this problem is that the system deployed in docker outputs a large amount of log content.

At this time, clearing can be performed by manual or scheduled tasks.

There are many solutions available online for /var/lib/docker/overlay2 space, some misleading statements require migration paths and other operations. In fact, the disk space occupies nothing to do with overlay (its usage is the same as the real disk usage). It is just a virtual file system of docker. The real file system is the former /dev/vda1. You can see that the path refers to the root directory, so you have to find where the garbage appears.

Usually, there will be the following directory in the same level as overlay2:

[root@iZ docker]# ls

builder buildkit containerd containers image network overlay2 plugins runtimes swarm tmp trust volumes

The log files that often occupy a lot of space are located under containers, and the following directory exists in this directory:

[root@iZ containers]# ls

123ace927dc96745bac8ae09d0feddbdef853ff089c831bc80547b2d1115b0ac 635619a5ce22b551c5c75095b8b01647b9a02c839be64cd465e1542bfbec8ee6 a979b62fc10ab0ac54af4799d40c2c5865099883ff124012328ab3a8587c1dda

There will be a directory file prefixed with the directory name and a suffix of "-" in the directory. Use the following command to see the size of the file:

ll -h

Then you can use the following command to clean up the contents of the file:

cat /dev/null > *-

The service can be restarted without restarting the cleaning process, but if allowed, it is recommended to restart the docker service.

After executing the df -h command here, you will find that the disk space occupied by overlay2 has been reduced.

Follow the official account: New Program Vision, a platform that allows you to simultaneously improve your soft power and hard technology

Unless otherwise stated, they are original articles from the Program New Vision. The link to this article must be marked in the form of a link.