Docker module
Lesson 13
Debug and cleanup
Read Compose logs, exec into a service, check Docker disk use, and prune without deleting your warehouse volume by accident.
beginner25 minRun on your machine
What you will be able to do
- Use compose logs and exec to debug a service
- Read docker system df
- Remove leftover containers and know when not to prune volumes
Why this matters for DE and AI
Failed jobs fill disks with images and anonymous volumes. No space left on device on a GPU box is often leftover Docker layers, not the dataset. You already practiced df in Linux. This lesson is the Docker-shaped version — plus the rule: do not prune volumes unless you mean to wipe databases.
Concepts
Debug order
docker compose ps -a— is it running, restarting, or Exited (1)?docker compose logs SERVICE— what did it print?docker compose exec SERVICE sh— only if it is still up.docker inspect— mounts and env when the YAML and the engine disagree.
Disk
docker system df
Shows images, containers, and volumes. Images grow every time you build without cleaning tags.
Cleanup ladder (small to large)
| Command | What it removes |
|---|---|
docker compose down |
Project containers and default network |
docker rm stopped containers |
One name |
docker image prune |
Dangling images (no tag) |
docker system prune |
Stopped containers, unused networks, dangling images |
docker system prune -a |
Also unused tagged images |
docker compose down -v / docker volume prune |
Volumes — Postgres data, named volumes |
docker rm -f NAME force-stops and removes one container. Fine for a named lab sleeper. Not a substitute for reading logs.
Practice on your machine
If the Compose database from the last lesson is down, start it:
cd ~/dcubes/docker-lab/compose-db
docker compose up -d
docker compose ps -a
docker compose logs --tail=30 db
What you should see: db Up (healthy) if the healthcheck passed. Logs include ready/accepting connections.
docker compose exec db pg_isready -U dcubes -d lab
What you should see: accepting connections
docker system df
Images will be the largest line after Postgres. Numbers differ. The habit is to look.
List volumes from this project:
docker volume ls | grep compose-db || docker volume ls
Compose prefixes volume names with the project directory (compose-db_pgdata or similar).
Stop the stack without wiping the database:
docker compose down
docker compose ps
Containers gone, volume still listed in docker volume ls.
Optional tidy of unused containers and dangling images only:
docker container prune -f
docker image prune -f
-f skips the yes/no prompt. We still did not pass --volumes.
Remove the named sleeper leftovers if any still exist from earlier lessons:
docker ps -a --filter name=dcubes-
If names appear, docker rm -f those names. Do not rm -f production containers; you have none on this laptop if you followed the module.
Common mistakes
- Pruning to fix a crash. Read logs. Prune does not explain
connection refused. down -vout of habit. That resets Postgres. Use it before a demo when you want empty.- Ignoring
docker system dfuntil the VM is full. Check after a week of pulling tags.
Next
Capstone: First Compose shift — load the movies CSV into Postgres with Compose.