Skip to main content

๐Ÿ›‘ Getting "No Space" Error After Using Docker for Some Time? Use These Commands to Clean Up ๐Ÿ›‘

docker logo



Docker is a fantastic tool for containerizing applications, allowing developers to package their software along with dependencies into lightweight, portable containers. These containers can run consistently across different environments, making Docker ideal for development, testing, and deployment. However, over time, unused images, containers, volumes, and networks can pile up, consuming significant disk space. If you’re encountering a "no space left on device" error or simply want to free up space, Docker provides several prune commands to help with cleanup. Let’s dive into each of these commands and how to use them effectively. ๐ŸŽ‰


1. docker image prune ๐Ÿ–ผ️

This command removes dangling images. Dangling images are layers that are no longer tagged or associated with a container.

Usage:

docker image prune

To remove unused images (not just dangling ones), use the -a flag:

docker image prune -a
Pro Tip: Combine the -a flag with filters for more control, like:
docker image prune -a --filter "until=1h"

This removes images that were unused for more than 1 hour. ๐Ÿ•’

docker image prune -a --filter "until=3h15m"

Removes images unused for more than 3 hours and 15 minutes. ⏳

docker image prune -a --filter "until=1h30m45s"

Removes images unused for more than 1 hour, 30 minutes, and 45 seconds. ⏱️

docker image prune -a --filter "until=24h"

Removes images unused for more than 24 hours. ๐Ÿ•›

docker image prune -a --filter "until=7d"

Removes images unused for more than 7 days. ๐Ÿ—“️


2. docker container prune ๐Ÿ› ️

This command removes all stopped containers. Stopped containers often take up disk space unnecessarily.

Usage:

docker container prune

You can filter stopped containers to target specific ones. For example:

docker container prune --filter "until=1h"

Removes containers that have been stopped for more than 1 hour. ๐Ÿ”ง

docker container prune --filter "until=3h15m"

Removes containers that have been stopped for more than 3 hours and 15 minutes. ๐Ÿ”

docker container prune --filter "until=1h30m45s"

Removes containers that have been stopped for more than 1 hour, 30 minutes, and 45 seconds. ๐Ÿ•ฐ️

docker container prune --filter "until=12h"

Removes containers that have been stopped for more than 12 hours. ⚙️

docker container prune --filter "until=7d"

Removes containers that have been stopped for more than 7 days. ๐Ÿ—“️


3. docker volume prune ๐Ÿ“ฆ

Volumes store data used by containers. Over time, unused volumes can consume a lot of space. This command removes all unused volumes.

Usage:

docker volume prune

If you want to avoid accidentally deleting critical volumes, double-check which ones are unused using:

docker volume ls -f dangling=true

4. docker network prune ๐ŸŒ

Unused networks can also contribute to clutter. This command removes networks that are not used by any container.

Usage:

docker network prune

As with other prune commands, you can use filters to target specific networks:

docker network prune --filter "until=1h"

Removes networks unused for more than 1 hour. ๐Ÿ•’

docker network prune --filter "until=3h15m"

Removes networks unused for more than 3 hours and 15 minutes. ⏳

docker network prune --filter "until=1h30m45s"

Removes networks unused for more than 1 hour, 30 minutes, and 45 seconds. ⏱️

docker network prune --filter "until=48h"

Removes networks unused for more than 48 hours. ๐ŸŒŸ

docker network prune --filter "until=7d"

Removes networks unused for more than 7 days. ๐Ÿ—“️


5. docker system prune ๐Ÿงน

This command is your go-to for general cleanup. It removes:

  • Stopped containers
  • Unused networks
  • Dangling images (images not associated with any container)
  • Build cache

Usage:

docker system prune

You’ll be prompted to confirm the action. If you want to bypass the confirmation, use the -f (force) flag:

docker system prune -f

Want to clean up unused volumes as well? Add the --volumes flag:

docker system prune --volumes

Note: Be cautious when using this command with --volumes, as it will remove all unused volumes, which could include data you may want to keep. ⚠️


Combining Commands for Maximum Cleanup ๐Ÿงฝ

To perform a thorough cleanup, you can combine these commands into a single script or execute them sequentially:

docker container prune -f
docker image prune -a -f
docker volume prune -f
docker network prune -f

Or, use the all-encompassing:

docker system prune -a --volumes -f

Warning: Be cautious when using -a and --volumes as they may remove data you still need. ⚠️


Proactive Space Management Tips ๐Ÿ“Š

  1. Use Docker Disk Usage Command: To understand what’s consuming space:

    docker system df
    
  2. Set Up Automatic Cleanup: Use tools like cron jobs or CI/CD pipelines to periodically run prune commands and keep your system tidy. ๐Ÿ•’

  3. Be Mindful with Volume Usage: Explicitly manage volumes to avoid orphaned data. ๐Ÿ“ฆ

  4. Monitor Build Cache: Large builds can leave behind substantial cache files. Regularly prune or optimize build steps to avoid excessive use. ⚙️


By using these prune commands effectively, you can keep your Docker environment clean and avoid the dreaded "no space left on device" error. Regular maintenance not only saves space but also ensures Docker runs smoothly for all your projects. ๐Ÿš€

Comments

Popular posts from this blog

How to install and configure termux on Android

Note: don’t install from the Google Play Store, it is a highly stripped-down version of the original The options present in my own priority order Download from GitHub releases Download using Fdroid download from GitHub releases Just go to GitHub releases , download the APK, and install it. We will see configuration steps later ! The only downside is you need to redownload on each release download using FDroid You can use Fdroid as package manager instead of Google play store Now download completed what’s next setup the nearest mirrors using termux-change-repo setup the storage using termux-setup-storage Do update and upgrade termux configure nearest mirrors Run termux-change-repo And it will scan all the nearest repos and configure the default one which is the nearest setup storage using termux-setup-storage It usually asks for some permissions and do some storage setup don’t remember what is actually do but used it to fix a problem some time ago do some PKG update and upgrade Run com...

Decoupling APIs Using Message Queues: Building Fault-Tolerant Applications ๐Ÿš€

  Decoupling APIs Using Message Queues: Building Fault-Tolerant Applications ๐Ÿš€ In the fast-paced world of modern software ๐ŸŒ, seamless communication between services is a cornerstone of effective system design. However, what happens when your API sends a request, and the server at the other end is busy—or worse, the request gets dropped? ๐Ÿ˜ฑ It’s a scenario many developers dread, but with proper design patterns, you can make your applications robust and fault-tolerant. One of the most powerful tools to address this challenge is Message Queues (MQs) ๐Ÿ“จ. In this blog, we’ll explore how decoupling APIs using MQs can transform your application into a more resilient system ๐Ÿ’ช. The Problem: Busy Servers and Dropped Requests ❌ In traditional client-server architecture, a client sends a request to the server, and the server processes it synchronously. This works fine until: The server is overwhelmed : High traffic spikes ๐Ÿ“ˆ can cause bottlenecks. Requests are time-sensitive : A de...

๐Ÿš€ Say Hello to UV: The Game-Changing Python Project Manager! ๐ŸŽ‰

  Ready to turbocharge your Python development? Introducing UV , the all-in-one Python package and project manager that's rewriting the rules! ⚡ Built with blazing-fast Rust, UV replaces tools like pip , pip-tools , poetry , pyenv , and more — all while being 10-100x faster . Whether you're installing dependencies, managing Python versions, or publishing your projects, UV makes it a breeze. Backed by Astral — the creators of Ruff — UV is here to revolutionize how you work with Python. ๐Ÿ✨ ๐ŸŒŸ Why UV Will Be Your New Favorite Tool ๐Ÿš€ All-in-One Convenience Replace a dozen tools with UV, your one-stop solution for Python package management, virtual environments, and more! ⚡️ Insane Speed Get things done 10-100x faster than traditional tools like pip . ๐Ÿ Python Version Pro? Yes, You! Install, switch, and manage Python versions with a single command. Never worry about compatibility again! ๐Ÿ› ️ Tools Made Easy Install and run Python-based CLI tools like a pro — ...