$npx -y skills add AlexAI-MCP/hermes-CCC --skill docker-managementManage Docker containers, images, volumes, networks, and Compose stacks - lifecycle ops, debugging, cleanup, and Dockerfile optimization.
| 1 | # Docker Management |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Use this skill to run, inspect, debug, and clean up Docker workloads. |
| 6 | - Prefer it when the task involves containers, images, networks, volumes, or Compose stacks. |
| 7 | - This skill covers both day-to-day lifecycle operations and practical debugging patterns. |
| 8 | |
| 9 | ## Core Mental Model |
| 10 | |
| 11 | - Images are immutable build artifacts. |
| 12 | - Containers are running or stopped instances of images. |
| 13 | - Volumes persist data outside the container filesystem lifecycle. |
| 14 | - Networks define service-to-service connectivity. |
| 15 | - Compose describes multi-container applications declaratively. |
| 16 | |
| 17 | ## Container Lifecycle |
| 18 | |
| 19 | - Create and run a container. |
| 20 | - Start a stopped container. |
| 21 | - Stop a running container. |
| 22 | - Restart a container after config or dependency issues. |
| 23 | - Remove a container when it is no longer needed. |
| 24 | |
| 25 | ## Common Lifecycle Commands |
| 26 | |
| 27 | ```bash |
| 28 | docker run -d --name myapp -p 8080:80 -v ./data:/data myimage |
| 29 | docker start myapp |
| 30 | docker stop myapp |
| 31 | docker restart myapp |
| 32 | docker rm myapp |
| 33 | ``` |
| 34 | |
| 35 | - `-d` runs the container in detached mode. |
| 36 | - `--name` assigns a stable container name. |
| 37 | - `-p 8080:80` maps host port `8080` to container port `80`. |
| 38 | - `-v ./data:/data` mounts a host path into the container. |
| 39 | |
| 40 | ## Run Command Pattern |
| 41 | |
| 42 | ```bash |
| 43 | docker run -d --name myapp -p 8080:80 -v ./data:/data myimage |
| 44 | ``` |
| 45 | |
| 46 | Use this pattern when you need: |
| 47 | |
| 48 | - background execution |
| 49 | - a predictable container name |
| 50 | - host-to-container port mapping |
| 51 | - local bind-mount persistence |
| 52 | |
| 53 | ## Inspect Running Containers |
| 54 | |
| 55 | ```bash |
| 56 | docker ps |
| 57 | docker ps -a |
| 58 | ``` |
| 59 | |
| 60 | - `docker ps` shows running containers only. |
| 61 | - `docker ps -a` shows all containers including exited ones. |
| 62 | - Exited containers often reveal crash-loop or entrypoint problems. |
| 63 | |
| 64 | ## Exec Into a Container |
| 65 | |
| 66 | ```bash |
| 67 | docker exec -it myapp bash |
| 68 | ``` |
| 69 | |
| 70 | - Use this when the container image includes `bash`. |
| 71 | - Fall back to `sh` for slimmer images: |
| 72 | |
| 73 | ```bash |
| 74 | docker exec -it myapp sh |
| 75 | ``` |
| 76 | |
| 77 | Useful checks inside a container: |
| 78 | |
| 79 | - verify file paths |
| 80 | - inspect environment variables |
| 81 | - test network reachability |
| 82 | - check permissions |
| 83 | - run the application command manually |
| 84 | |
| 85 | ## View Logs |
| 86 | |
| 87 | ```bash |
| 88 | docker logs -f myapp |
| 89 | ``` |
| 90 | |
| 91 | - Use `-f` to follow logs live. |
| 92 | - Add `--tail 100` to reduce noise when the log is very large. |
| 93 | - Container logs are the fastest first stop for boot failures. |
| 94 | |
| 95 | ## List Images, Volumes, and Networks |
| 96 | |
| 97 | ```bash |
| 98 | docker images |
| 99 | docker volume ls |
| 100 | docker network ls |
| 101 | ``` |
| 102 | |
| 103 | - `docker images` helps identify build tags and old layers. |
| 104 | - `docker volume ls` helps track stateful storage. |
| 105 | - `docker network ls` is useful when debugging Compose service communication. |
| 106 | |
| 107 | ## Build Images |
| 108 | |
| 109 | ```bash |
| 110 | docker build -t myapp:latest . |
| 111 | ``` |
| 112 | |
| 113 | - Tag images explicitly. |
| 114 | - Rebuild after Dockerfile changes, dependency changes, or copy-step changes. |
| 115 | - Keep the build context small with a `.dockerignore`. |
| 116 | |
| 117 | ## Dockerfile Baseline |
| 118 | |
| 119 | ```dockerfile |
| 120 | FROM python:3.12-slim |
| 121 | |
| 122 | WORKDIR /app |
| 123 | COPY requirements.txt . |
| 124 | RUN pip install --no-cache-dir -r requirements.txt |
| 125 | |
| 126 | COPY . . |
| 127 | CMD ["python", "app.py"] |
| 128 | ``` |
| 129 | |
| 130 | - Copy dependency manifests before source code to improve layer caching. |
| 131 | - Use a narrow base image unless native toolchains are required. |
| 132 | |
| 133 | ## Multi-Stage Dockerfile Pattern |
| 134 | |
| 135 | ```dockerfile |
| 136 | FROM node:22 AS build |
| 137 | WORKDIR /src |
| 138 | COPY package*.json ./ |
| 139 | RUN npm ci |
| 140 | COPY . . |
| 141 | RUN npm run build |
| 142 | |
| 143 | FROM nginx:alpine |
| 144 | COPY --from=build /src/dist /usr/share/nginx/html |
| 145 | HEALTHCHECK CMD wget -qO- http://localhost/ || exit 1 |
| 146 | ``` |
| 147 | |
| 148 | - Build dependencies stay in the builder stage. |
| 149 | - The final stage is smaller and carries less attack surface. |
| 150 | - Multi-stage builds are standard for frontend artifacts, Go binaries, and compiled assets. |
| 151 | |
| 152 | ## Health Checks |
| 153 | |
| 154 | - Define health checks in the Dockerfile when the service has a meaningful liveness probe. |
| 155 | - Health checks help Compose and orchestration layers reason about readiness. |
| 156 | |
| 157 | Example: |
| 158 | |
| 159 | ```dockerfile |
| 160 | HEALTHCHECK --interval=30s --timeout=5s --retries=3 CMD curl -fsS http://localhost:8080/health || exit 1 |
| 161 | ``` |
| 162 | |
| 163 | - Prefer an explicit application health endpoint. |
| 164 | - Avoid health checks that pass before dependencies are ready unless that is intentional. |
| 165 | |
| 166 | ## Docker Compose Basics |
| 167 | |
| 168 | ```bash |
| 169 | docker compose up -d |
| 170 | docker compose logs |
| 171 | docker compose down |
| 172 | ``` |
| 173 | |
| 174 | - `docker compose up -d` starts the stack in the background. |
| 175 | - `docker compose logs` shows service logs across the stack. |
| 176 | - `docker compose down` stops and removes the stack's containers and network. |
| 177 | |
| 178 | ## Minimal Compose Example |
| 179 | |
| 180 | ```yaml |
| 181 | services: |
| 182 | app: |
| 183 | build: . |
| 184 | ports: |
| 185 | - "8080:8080" |
| 186 | environment: |
| 187 | APP_ENV: development |
| 188 | depends_on: |
| 189 | - redis |
| 190 | |
| 191 | redis: |
| 192 | image: redis:7-alpine |
| 193 | ``` |
| 194 | |
| 195 | - Compose is the default choice for local multi-service d |