Table of contents
![blog cover](https://res.cloudinary.com/du34z6lpw/image/upload/v1710053099/assets/try-hard_se9jtl.jpg)
Reclaiming Disk Space in Docker
Docker
Docker
One day, I encountered a troubling issue when my Amazon EC2 server ran out of storage space. After investigating, I discovered that Docker was consuming a significant portion of this precious space, largely due to the accumulation of cache. In this blog post, I'll delve into why Docker cache can become a storage hog and provide you with detailed steps on how to reclaim that vital disk space.
Docker stores various resources, including images and containers, in a storage driver, which can lead to a substantial increase in disk space usage over time. Docker's default storage driver, devicemapper, is known for its inefficiency in managing storage, which often contributes to this problem.
Check Docker Disk Usage
Begin by examining your Docker storage usage with the docker system df command. This will give you an overview of how much space Docker is currently consuming.
// language: bash docker system df
Remove Unused Resources
Prune All Unused Resources
Use the docker system prune command to remove all unused data, including stopped containers and dangling images.
Use the docker system prune command to remove all unused data, including stopped containers and dangling images.
// language: bash docker system prune
Remove Specific Containers and Images
If you need to delete particular containers or images, you can do so using the following commands:
To remove a container:
// language: bash # Show all containers docker container ls # Remove container docker rm <container_name_or_id>
// language: bash # Show all images docker image ls # Remove image docker rmi <image_name_or_id>
Clear Build Cache
If you want to clear the build cache, use the docker builder prune command. This command removes all build cache, which can be quite useful for freeing up additional space.
// language: bash docker builder prune
Adjust Docker Disk Usage
For long-term improvements, consider changing the Docker storage driver to overlay2. This driver is more efficient in managing disk space. Edit the Docker daemon configuration file, typically located at /etc/docker/daemon.json, and add the following configuration:
{ "storage-driver": "overlay2" }
Created at
2023-10-21 13:29:22 +0700
Related blogs
Docker compose basics: Essential commands
Docker has revolutionized the way we develop, package, and deploy applications. It allows us to containerize our applications, providing a consistent ...
Docker
Docker
2023-05-22 18:56:28 +0700
How to Manage and Renew SSL Certificates Using Docker Compose
Securing your website with SSL certificates is essential to protect data transmitted between the server and client. Managing and renewing SSL certific...
Docker
Docker
2024-05-26 15:44:03 +0700