User Tools

Site Tools


rdm-dev:docker

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rdm-dev:docker [2025/09/25 08:51]
torkhov [Step 1: Understanding What Takes Space]
rdm-dev:docker [2025/11/18 13:41] (current)
torkhov
Line 1: Line 1:
 A safe place to share everything about Docker. 8-O A safe place to share everything about Docker. 8-O
  
-====== Docker Cleanup Guide: Reclaiming Disk Space ======+[[rdm-dev:docker:cleanup|Docker Cleanup Guide: Reclaiming Disk Space]]
  
  
-Docker is an amazing technology that backs up each project I work onWithout diving too much into details, let's go through a workflow on how to clean up space that Docker takes up on your system. +[[rdm-dev:docker:exe|fix for: Docker-credential-desktop.exe executable file not found in $PATH]]
-=====  +
-Understanding Docker's Storage Model =====+
  
 +[[rdm-dev:docker:ip|How to get an IP of a container?]]
  
-The concept behind Docker is that it wants to cache every image it runs. An instance of a running image is a container, and they also use disk space. Finally, to persist data between container uptimes, Docker uses volumes to persist data on the host system.+[[rdm-dev:docker:it|How to connect to a docker container via terminal?]]
  
-==== Step 1: Understanding What Takes Space ==== 
  
  
-The first step is always understanding what's consuming your disk space: +Container name in Docker is: compose_stack-service-version 
- +  * **compose_stack** is the dir name where the docker-compose is locatedCan overwrite with -p flag of the docker-compose command
-```bash +  * **service** is the second level of declaration in the docker-composefor ELMO it is: 
-docker system df +  *  
-``` +  * * services
- +  * * *  db
-This command shows you a high-level overview, but for detailed analysis, use: +  * * *  web
- +   
-```bash +  * **version** is usually 1it varies if you scale the service.  
-docker system df -v +Have fun 🤣 and remember
-``` +You can overwrite the name of a single container using the **--name** command-line flag with **docker run**, or you can use the **container_name:** directive in Docker Compose file.
- +
-This verbose output breaks down Docker's storage into four key components: +
- +
-===  1. Images - The Blueprint Cache === +
- +
- +
-**What they are:** Templates used to create containers +
-**Why they accumulate:** Docker caches every image you pull or build +
-- **Space impact:** Often the largest consumer (can be 20-30GB+) +
-- **Reclaimable:** Unused images can be safely removed +
- +
-=== 2Containers The Running Instances === +
- +
- +
-- **What they are:** Actual running or stopped instances of images +
-**Why they accumulate:** Stopped containers aren't automatically deleted +
-- **Space impact:** Usually minimal, but can add up +
-- **Reclaimable:** Stopped containers can be safely removed if you can recreate them +
- +
-=== 3Local Volumes - The Data Persistence Layer === +
- +
- +
-**What they are:** Persistent storage for container data +
-**Why they accumulate:** Created for databases, config files, user data +
-**Space impact:** Can be substantial, especially database volumes +
-- **Reclaimable:** ⚠️ **CAUTION** - Only remove if you're sure data isn't needed +
- +
-=== 4Build Cache - The Development Speedup === +
- +
- +
-- **What it is:** Cached layers from building Docker images +
-**Why it accumulates:** Each docker build creates cached layers +
-**Space impact:** Can easily reach 15-20GB+ during active development +
-- **Reclaimable:** Safe to remove, but rebuilds will be slower +
- +
- +
- +
----- +
-[[https://docs.portainer.io/user/docker/containers/stats|Checking the resource usage in Portainer]] +
-==== Step 2: Systematic Cleanup Workflow ==== +
- +
- +
-===  Investigate Before You Delete === +
- +
- +
-```bash +
-# List all images with sizes +
-docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" +
- +
-# List all containers (running and stopped) +
-docker ps -a +
- +
-# List all volumes +
-docker volume ls +
- +
-# Check build cache details +
-docker buildx du +
-``` +
- +
-===  Safe Cleanup Commands === +
- +
- +
-**Remove unused images (usually the biggest space saver):*+
-```bash +
-docker image prune -a  # Removes all unused images +
-``` +
- +
-**Remove stopped containers:** +
-```bash +
-docker container prune  # Removes all stopped containers +
-# Or selectively: docker rm [container_id] [container_id] +
-``` +
- +
-**Remove unused volumes (⚠️ BE CAREFUL - this deletes data):*+
-```bash +
-docker volume prune  # Only removes truly unused volumes +
-# Or selectivelydocker volume rm [volume_name] +
-``` +
- +
-**Remove build cache:** +
-```bash +
-docker builder prune -a  # Safe to remove, just slows future builds +
-``` +
- +
-====  The Nuclear Option ==== +
- +
- +
-If you want to reclaim maximum space and start fresh: +
- +
-```bash +
-docker system prune -a --volumes +
-``` +
- +
-> ⚠️ **Warning:** This removes everything unused - imagescontainers, volumes, networks, and build cache+
- +
-=====  Step 3Sustainable Cleanup Strategy ===== +
- +
- +
-Rather than the "delete everything and hope it's fine" approach, I recommend this workflow: +
- +
-1. **Weekly maintenance:** Run `docker system df -v` to monitor growth +
-2. **Monthly cleanup:** Remove unused images and build cache +
-3. **Project completion:** Clean up project-specific volumes and images +
-4. **Before major updates:** Full cleanup to start with a clean slate +
- +
-## Pro Tips for Long-term Management +
-  +
-  * **Use .dockerignore:** Reduces image sizes and build cache bloat +
-  * **Multi-stage builds:** Keep final images lean +
-  * **Regular pruning:** Don't let cache accumulate to 50GB+ before cleaning +
-  * **Volume data:** Backup important container data separately +
- +
---- +
- +
-Happy codingand may your Docker storage never exceed your SSD capacity! 🐳 +
- +
-**Remember:** The goal isn't to delete everything, but to maintain balance between performance (caching) and disk usage. Clean regularly, but thoughtfully.+
rdm-dev/docker.1758790281.txt.gz · Last modified: 2025/09/25 08:51 by torkhov