Each layer in an image is a folder inside the /usr/lib/docker/overlay2/ folder. Lets learn some way to clean up / identify contents of /var/lib/docker/overlay

Is it safe to clean docker/overlay2 ???

Docker uses /var/lib/docker to store your images, containers, and local named volumes. Deleting this can result in data loss and possibly stop the engine from running. The overlay2 subdirectory specifically contains the various filesystem layers for images and containers.

But I would say, yes it's safe when you know what you are doing. In our case, we don't want to delete active containers or images. So let's the delete the unused ones and free up some space !

Check Disk usage by docker first

$ docker system df

Sample Output:

TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              235                 9                   9.029GB             8.219GB (91%)
Containers          17                  9                   29.59MB             11.82MB (39%)
Local Volumes       20                  8                   80.72MB             37.08MB (45%)
Build Cache         0                   0                   0B                  0B