This shows you the differences between two versions of the page.
| 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 | ||
| - | ====== | + | [[rdm-dev: |
| - | Docker | + | [[rdm-dev: |
| - | ===== | + | |
| - | Understanding Docker' | + | |
| + | [[rdm-dev: | ||
| - | 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: |
| - | ==== Step 1: Understanding What Takes Space ==== | ||
| - | The first step is always understanding what's consuming your disk space: | + | Container name in Docker |
| - | + | * **compose_stack** is the dir name where the docker-compose is located. Can overwrite with -p flag of the docker-compose command. | |
| - | ```bash | + | * **service** is the second level of declaration in the docker-compose. for ELMO it is: |
| - | docker system df | + | * |
| - | ``` | + | * * services: |
| - | + | * * * | |
| - | This command shows you a high-level overview, but for detailed analysis, use: | + | * * * |
| - | + | ||
| - | ```bash | + | * **version** is usually 1, it 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 a Docker Compose file. |
| - | + | ||
| - | This verbose output breaks down Docker' | + | |
| - | + | ||
| - | === 1. Images - The Blueprint Cache === | + | |
| - | + | ||
| - | + | ||
| - | - **What they are:** Templates used to create containers | + | |
| - | - **Why they accumulate: | + | |
| - | - **Space impact:** Often the largest consumer (can be 20-30GB+) | + | |
| - | - **Reclaimable: | + | |
| - | + | ||
| - | === 2. Containers | + | |
| - | + | ||
| - | + | ||
| - | - **What they are:** Actual running or stopped instances | + | |
| - | - **Why they accumulate: | + | |
| - | - **Space impact:** Usually minimal, but can add up | + | |
| - | - **Reclaimable: | + | |
| - | + | ||
| - | === 3. Local Volumes - The Data Persistence Layer === | + | |
| - | + | ||
| - | + | ||
| - | - **What they are:** Persistent storage for container data | + | |
| - | - **Why they accumulate: | + | |
| - | - **Space impact:** Can be substantial, | + | |
| - | - **Reclaimable: | + | |
| - | + | ||
| - | === 4. Build Cache - The Development Speedup === | + | |
| - | + | ||
| - | + | ||
| - | - **What | + | |
| - | - **Why it accumulates: | + | |
| - | - **Space impact:** Can easily reach 15-20GB+ during active development | + | |
| - | - **Reclaimable: | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | ---- | + | |
| - | [[https:// | + | |
| - | ==== 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: | + | |
| - | ``` | + | |
| - | + | ||
| - | **Remove unused volumes (⚠️ BE CAREFUL - this deletes data):** | + | |
| - | ```bash | + | |
| - | docker volume prune # Only removes truly unused volumes | + | |
| - | # Or selectively: docker 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 | + | |
| - | ``` | + | |
| - | + | ||
| - | > ⚠️ | + | |
| - | + | ||
| - | ===== Step 3: Sustainable Cleanup Strategy ===== | + | |
| - | + | ||
| - | + | ||
| - | Rather than the " | + | |
| - | + | ||
| - | 1. **Weekly maintenance: | + | |
| - | 2. **Monthly cleanup:** Remove unused images and build cache | + | |
| - | 3. **Project completion: | + | |
| - | 4. **Before major updates:** Full cleanup to start with a clean slate | + | |
| - | + | ||
| - | ## Pro Tips for Long-term Management | + | |
| - | + | ||
| - | | + | |
| - | * **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 coding, and may your Docker storage never exceed your SSD capacity! 🐳 | + | |
| - | + | ||
| - | > **Remember:** The goal isn't to delete everything, but to maintain | + | |