Sunday, December 25, 2022

Detailed steps to check Docker disk usage

Doing a Quick Check

docker system df

sudo du -sh /var/lib/docker/

This command shows static images, containers that have made changes to their filesystem (e.g., log files), and volumes bound to the containers.


Each version of an image is separate, but it’s stored in layers, so multiple new versions won’t take up twice as much storage space. You can view all images with image ls:



Cleaning these is easy; you don’t want to remove images of running containers, of course, but removing old images is fine—they’ll simply be re-downloaded when needed.



docker image prune -a

docker image rm 3a8d8f76e7f8f



Containers are a bit trickier to track down, since they can use data in many different ways:


1) Underlying image: each container will need to store its image, but this is reused across containers.

2) Modification layer: if a container writes to its filesystem, such as log files, it will be saved in a new layer on top of the underlying image. This is unique to each container.

3) Volumes: containers can have virtual drives mounted to them, which store data directly on disk outside the Docker storage system.

4) Bind Mounts: containers can optionally access directories on the host directly.


docker system df 


Here, this shows the size on disk, as well as the virtual size (which includes the shared underlying image). Since these containers aren’t using any storage outside their bind mounts, the size is zero bytes.


And best option is 


If you have direct access to the server running Docker, you can pop open a shell in the container:


sudo docker exec -it containerID /bin/bash



references:

https://www.howtogeek.com/devops/how-to-check-disk-space-usage-for-docker-images-containers/#:~:text=Doing%20a%20Quick%20Check,size%20of%20the%20entire%20directory. 

No comments:

Post a Comment