Docker disk space cleanup, done in one command!
Whether it's Linux or Windows, Docker generates a massive amount of junk files after running for a while! Today I learned a command that freed up 30GB of my Windows hard drive space in one go!
Rendering...
Whether on Linux or Windows, Docker can accumulate a massive amount of junk files over time! Today, I learned a command that freed up 30GB of space on my Windows machine in one go! `docker system prune -a --volumes` is an official, one-click, powerful cleanup command that can instantly free up tens of gigabytes of hard drive space. *Heads-up: If you're unsure whether you need to keep any volumes, please read the alternative solutions at the end of this article.* ## I. What Does This Command Delete? This command one-click wipes out **all unused** resources in Docker, specifically including: - **`-a` (or `--all`)**: Deletes all stopped containers, and **all images not used by running containers** (no longer limited to dangling images). - **`--volumes`**: Deletes **all data volumes not mounted by any container** (often residual database or application data). - **Networks and Caches**: Deletes unused networks and build caches. > ⚠️ **Core Principle**: As long as a container is currently in a **Running** state, the containers, images, and data volumes it depends on will **absolutely not** be deleted. ## II. Risk Warning (Must Read Before Execution) Before hitting Enter, please confirm: 1. You haven't temporarily stopped (Stop) important containers that you intend to start later. 2. You haven't intentionally left orphaned data volumes (e.g., MySQL data volumes) for future data recovery. 3. **Once deleted, data cannot be recovered!** ## III. Practical Usage Steps ### 1. Check Running Status First, ensure your important containers are running: ```Bash docker ps ``` ### 2. Execute Cleanup Enter the command in your terminal: ```Bash docker system prune -a --volumes ``` ### 3. Confirm Execution The system will pop up a warning and ask for confirmation. Enter **`y`** and press Enter: ```Plaintext Are you sure you want to continue? [y/N] y ``` ### 4. The Results After the cleanup is complete, the reclaimed space will be displayed at the bottom: ```Plaintext Total reclaimed space: 14.52GB # Successfully reclaimed 14.52 GB of space! ``` ## Alternative Solutions (Gentler Cleanup) A gentler approach is to remove some parameters. Here are the specifics: ```Bash # Only deletes dead containers and dangling images (safest, doesn't delete large images or data) docker system prune # Doesn't delete data volumes, only dead containers and unused images docker system prune -a ```
Comments
Please login to view and post comments
Go to Login