We have installed Docker on a virtual machine (VM) hosted on Azure, where image builds are frequently performed. After building the images, they are pushed to an artifact registry. To free up space on the VM, we use the docker system prune -f -a --volumes command, which is intended to remove unused volumes, images, and build cache. However, despite executing this command, the Docker engine continues to utilize a significant amount of memory. We are unsure of the root cause and, as a temporary solution, have been extending the size of the VM to accommodate the increasing memory usage. Additionally, we prefer not to delete the build cache as it is essential for maintaining faster build times.
In the /var/lib/docker directory, we observe that various folders, including images, network, overlay2, plugins, runtimes, swarm, tmp, and volumes, are present, with the overlay2 folder consuming a substantial amount of space. This folder contains image-related and container-related directories. After pushing images to the artifact registry, we believe these folders and images in overlay2 can be deleted to free up space. However, we are uncertain about the potential consequences of deleting the overlay2 folder and its contents, leading us to avoid this action and instead extend the size of the VM. Additionally, we prefer not to delete the build cache as it is essential for maintaining faster build times.