Docker overlay2 cleanup refers to clearing out this unused or obsolete data to free up disk space. Let’s learn more about Docker overlay2 cleanup process in this latest blog. At Bobcares, with our Docker Hosting Support Services, we can handle your Docker issues.
Overview
Docker Overlay2 Cleanup
Docker stores the images, containers, and local named volumes under /var/lib/docker and each layer of an image is a separate folder within the /usr/lib/docker/overlay2/ folder. In the overlay2 subdirectory, we can explicitly locate the different filesystem layers for images and containers.
In some cases, removing the overlay will cause data loss and possibly cause the engine to crash. However, when we are genuinely conscious of what we are doing, we can do it securely. In this article, we will look into the steps to clean up Docker Overlay2 contents, mainly the unused ones.
Methods to Clean Up Docker Overlay2
1. Using the docker system prune Command
- Firstly, we have to check the disk usage by Docker using the following command:
$ docker system df
The output will look like:
TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 300 9 9.01GB 8.119GB (91%) Containers 15 7 9.59MB 11.82MB (39%) Local Volumes 21 8 80.72MB 38.08MB (45%) Build Cache 0 0 0B 0B
- Docker does not by default remove the images even if they are not in use. To remove unused photos, we can use the below command:
docker image prune --all
- In order to clean up unused containers and images, we can use the docker system prune.
docker system prune --all
- A prune will never remove consists of:
- Operational containers
- The container’s logs
- Changes those containers made to the filesystem
- Additionally, during this garbage collection, anything created outside of the standard docker folders might not be visible to the docker. This can be the result of another program writing to this directory or an earlier Docker engine setup.
- Whenever we need to completely refresh docker to a clean state, then it is recommended to delete the entire directory, not just sub-directories like overlay2.
2. Manually Removing Unused Data
When we want more granular control over the cleanup process, we can manually identify and remove unused data. The steps include:
- Identifying unused images: Initially, use docker images to list all images. Then, find images that are no longer needed.
- Removing unused images: Then, we use docker rmi to remove specific images.
- Removing unused containers: Also, use docker rm to remove containers.
- Removing unused volumes: Lastly, we use docker volume rm to remove volumes.
3. Automatic Cleanup Steps
Docker may be set up to periodically delete unnecessary data automatically. In order to do so, we must add the following to the Docker daemon configuration file (/etc/docker/daemon.json):
{
"prune": true,
"prune_interval": "1h"
}
Every hour, this will automatically remove any unnecessary data. We can adjust the prune_interval time according to our need.
Main Considerations
- Frequent Cleanup: To avoid using too much disk space, it is advised to carry out routine cleanup.
- Watch Storage Usage: Keep an eye on how much storage is being used by the Docker host to determine when cleanup may be required.
- Optimize Image Layers: We can cut down on the quantity of data saved in the Overlay2 driver by building smaller, more effective image layers.
[Need help with another query? Reach out to us.]
Conclusion
In this article, we have covered the details from our Tech team on Docker overlay2 cleanup process. We’ve included the cleanup steps using docker prune command, manual steps, and automatic steps.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
Well…..
docker system prune –all
WARNING! This will remove:
– all stopped containers
– all networks not used by at least one container
– all images without at least one container associated to them
– all build cache
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
30Gb data from 2020 still there….
Hi,
Please contact our support team via live chat(click on the icon at right-bottom).