| name | docker |
| description | Manage Docker containers and Compose stacks: build, run, stop, logs, exec, prune, multi-service orchestration. |
| category | system |
| maturity | stable |
| tags | ["containers","docker-compose","orchestration","images","volumes"] |
Docker Skill
Manage Docker containers and Compose stacks: build, run, stop, logs, exec, prune, multi-service orchestration.
Use When
- Building/running containers or debugging container issues
- Setting up docker-compose stacks
- Managing images, volumes, networks
- Containerizing applications
- Multi-service orchestration
Quick Reference
Container Lifecycle
docker run -d --name myapp -p 8080:80 -e NODE_ENV=production --restart unless-stopped myimage:latest
docker exec -it myapp bash
docker logs -f --tail 100 --timestamps myapp
docker stop myapp && docker rm myapp
docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
Building Images
docker build -t myapp:latest .
docker build --target production -t myapp:prod .
docker build --build-arg VERSION=1.2.3 -t myapp:1.2.3 .
docker build --no-cache -t myapp:latest .
Docker Compose
docker compose up -d
docker compose up -d postgres
docker compose up -d --build
docker compose logs -f --tail 50
docker compose down -v
docker compose up -d --scale worker=3
docker compose exec web bash
docker compose ps
Debugging
docker inspect myapp
docker stats --no-stream
docker top myapp
docker cp myapp:/app/logs/error.log ./error.log
docker inspect --format='{{.State.ExitCode}} {{.State.Error}}' myapp
docker network ls
docker network inspect bridge
docker run --rm -it --entrypoint sh myimage:latest
Cleanup
docker system prune -f
docker system prune -af --volumes
docker system df
docker image prune -f
docker image prune -a --filter "until=24h"
Volumes & Networks
docker volume create mydata
docker run -d -v mydata:/app/data myapp
docker run -d -v $(pwd)/config:/app/config:ro myapp
docker network create mynet
docker run -d --network mynet --name api myapi
docker run -d --network mynet --name web myweb
Helper Scripts
Generate docker-compose template
bash scripts/compose-gen.sh <project-name> [services...]
Check container health
bash scripts/health-check.sh [container-name|all]
Cleanup/prune with safety
bash scripts/cleanup.sh [--aggressive]
Common Patterns
Dockerfile — Node.js app
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
RUN addgroup -g 1001 appgroup && adduser -u 1001 -G appgroup -s /bin/sh -D appuser
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
USER appuser
EXPOSE 3000
CMD ["node", "dist/index.js"]
Dockerfile — Python app
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
USER nobody
EXPOSE 8000
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "app:app"]
Troubleshooting
| Problem | Solution |
|---|
| Container exits immediately | Check docker logs myapp, verify CMD/ENTRYPOINT |
| Port already in use | lsof -i :8080 or change host port |
| Permission denied on volume | Check UID mapping, use --user $(id -u):$(id -g) |
| Can't connect between containers | Use same network, reference by container name |
| Out of disk space | docker system prune -af --volumes |
| Build cache too large | docker builder prune -af |
| DNS issues in container | docker run --dns 8.8.8.8 or check /etc/resolv.conf |