Bobcares

Docker Overlay2 Cleanup | A Detailed Guide

by | Sep 26, 2022

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
  1. Docker Overlay2 Cleanup
  2. Methods to Clean Up Docker Overlay2
  3. Main Considerations
  4. Conclusion

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.

docker overlay2 cleanup

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.

2 Comments

  1. Yello

    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….

    Reply
    • Hiba Razak

      Hi,
      Please contact our support team via live chat(click on the icon at right-bottom).

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF