DEV Community

keshav Sandhu
keshav Sandhu

Posted on

2

How to Manage Docker Disk Space and Resolve Storage Issues on Windows

Docker is a fantastic tool for containerization, but it can sometimes consume large amounts of disk space, especially when backend errors or excessive logs occur. On Windows, users often notice their C drive filling up, and the disk space only returns to normal after restarting the system. In this post, we’ll explore why this happens and how to fix it without restarting your computer.


1. Understanding Docker Disk Usage

Docker manages its containers, images, and logs using storage layers. These layers can quickly accumulate disk space, especially if:

  • Logs from containers are large due to errors or verbose output.
  • Build cache is not cleaned after frequent image builds.
  • Temporary storage layers grow with file changes.

2. Cleaning Up Docker Logs

Container logs can grow indefinitely if not managed. Here's how to clear them:

  1. Limit Log Size: Update the Docker configuration to cap log file sizes. Add this to your daemon.json file:
   {
     "log-driver": "json-file",
     "log-opts": {
       "max-size": "10m",
       "max-file": "3"
     }
   }
Enter fullscreen mode Exit fullscreen mode

Restart Docker for this to take effect.

  1. Clear Existing Logs: Navigate to the C:\ProgramData\Docker\containers\ directory and delete .log files to free up space.

3. Pruning Build Cache and Unused Data

Docker’s build cache can grow over time, but you can clean it up:

  • Run:
  docker builder prune --all
Enter fullscreen mode Exit fullscreen mode
  • To remove unused images, containers, and volumes:
  docker system prune -a --volumes
Enter fullscreen mode Exit fullscreen mode

4. Managing Overlay Storage

Temporary filesystem layers can consume significant space.

  1. Check usage:
   docker system df
Enter fullscreen mode Exit fullscreen mode
  1. Stop all running containers to clear temporary storage:
   docker stop $(docker ps -q)
Enter fullscreen mode Exit fullscreen mode

5. Removing Dangling Volumes

Unused volumes can pile up if containers are removed without their volumes.

  1. Identify dangling volumes:
   docker volume ls -f dangling=true
Enter fullscreen mode Exit fullscreen mode
  1. Remove them:
   docker volume prune
Enter fullscreen mode Exit fullscreen mode

6. Fixing Disk Space Without Restarting Your PC

Instead of rebooting:

  1. Stop all containers:
   docker stop $(docker ps -q)
Enter fullscreen mode Exit fullscreen mode
  1. Clear unused resources:
   docker system prune -a --volumes
Enter fullscreen mode Exit fullscreen mode
  1. If needed, manually clear logs in the C:\ProgramData\Docker directory.

Conclusion

By regularly maintaining Docker's storage with pruning commands and limiting log sizes, you can prevent Docker from consuming excessive disk space. These steps ensure smoother operation without requiring a system restart.

😊

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay