docker-build
vndee/engineering-skills/.claude/skills/docker-build/SKILL.md
Use when creating or updating Docker configurations, Dockerfiles, or docker-compose setups for Go, Python, or React projects
Skill3 starsChanged 7 months ago
- Reads credentials
What's in it
- Docker Build Patterns
- Overview
- Go Dockerfile (Multi-stage)
- Python Dockerfile (Multi-stage with uv)
- React Dockerfile (Bun + nginx)
- nginx.conf
- Docker Compose (Full Stack — Go)
- Docker Compose (Full Stack — Python)
- .dockerignore
- Optimization Checklist
- Health Checks
- Chains
---
name: docker-build
description: Use when creating or updating Docker configurations, Dockerfiles, or docker-compose setups for Go, Python, or React projects
---
# Docker Build Patterns
## Overview
Production-ready Docker configurations for Go, Python/FastAPI, and React/Bun. Multi-stage builds, Docker Compose for local dev, and optimization patterns.
**Core principle:** Small images, fast builds, layer caching. Dev and prod parity.
## Go Dockerfile (Multi-stage)
```dockerfile
FROM golang:1.23-alpine AS builder
RUN apk add --no-cache git
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /bin/api ./cmd/api
FROM alpine:3.20
RUN apk add --no-cache ca-certificates tzdata
COPY --from=builder /bin/api /bin/api
COPY migrations/ /migrations/
EXPOSE 8000
ENTRYPOINT ["/bin/api"]
```
## Python Dockerfile (Multi-stage with uv)
```dockerfile
FROM python:3.12-slim AS builder
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-editable
COPY src/ src/
COPY alembic/ alembic/
COPY alembic.ini .
FROM python:3.12-slim
COPY --from=builder /app /app
WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH"
EXPOSE 8000
CMD ["uvicorn", "src.main:create_app", "--factory", "--host", "0.0.0.0", "--port", "8000"]
```
## React Dockerfile (Bun + nginx)
```dockerfile
FROM oven/bun:1 AS build
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
COPY . .
RUN bun run build
FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
```
### nginx.conf
```nginx
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
location /api/ {
proxy_pass http://api:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location / {
try_files $uri $uri/ /index.html;
}
gzip on;
gzip_types text/css application/javascript application/json;
}
```
## Docker Compose (Full Stack — Go)
```yaml
services:
api:
build: ./backend
ports: ["8000:8000"]
environment:
DATABASE_URL: postgres://app:secret@postgres:5432/app?sslmode=disable
REDIS_URL: redis://redis:6379
depends_on:
postgres: { condition: service_healthy }
volumes: ["./backend:/app"] # dev only
command: air # dev only
web:
build: ./frontend
ports: ["5173:5173"]
volumes: ["./frontend/src:/app/src"] # dev only
command: bun dev --host # dev only
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: secret
POSTGRES_DB: app
ports: ["5432:5432"]
volumes: [pgdata:/var/lib/postgresql/data]
healthcheck:
test: pg_isready -U app
interval: 5s
retries: 5
redis:
image: redis:7-alpine
ports: ["6379:6379"]
volumes:
pgdata:
```
## Docker Compose (Full Stack — Python)
Replace the `api` service:
```yaml
api:
build: ./backend
ports: ["8000:8000"]
environment:
DATABASE_URL: postgresql+asyncpg://app:secret@postgres:5432/app
REDIS_URL: redis://redis:6379
depends_on:
postgres: { condition: service_healthy }
volumes: ["./backend:/app"]
command: uvicorn src.main:create_app --factory --reload --host 0.0.0.0
```
## .dockerignore
```
.git
.env
node_modules
__pycache__
*.pyc
.pytest_cache
.mypy_cache
.ruff_cache
tmp/
dist/
bin/
```
## Optimization Checklist
| Technique | Benefit |
|-----------|---------|
| Multi-stage builds | Smaller final image |
| Copy dependency files first | Layer caching |
| `--frozen-lockfile` / `--frozen` | Reproducible builds |
| Alpine / slim base | Smaller image |
| `.dockerignore` | Faster context |
| `CGO_ENABLED=0` (Go) | Static binary |
| `--no-dev` (Python) | Skip dev deps |
## Health Checks
```yaml
# For API containers
healthcheck:
test: wget -q --spider http://localhost:8000/health || exit 1
interval: 10s
timeout: 5s
retries: 3
```
## Chains
- **REQUIRED:** Update CLAUDE.md with Docker commands (`claude-md`)
- **Invoked by:** `go-scaffold` / `py-scaffold` / `react-scaffold` (during project setup)
- **Feeds into:** `ci-pipeline` (build stage) → `deploy` (production deployment)
More agent context in vndee/engineering-skills
36 other files this repository gives its agents.
Skill
- adr.claude/skills/adr/SKILL.md
- analytics.claude/skills/analytics/SKILL.md
- api-contract.claude/skills/api-contract/SKILL.md
- api-design.claude/skills/api-design/SKILL.md
- ci-pipeline.claude/skills/ci-pipeline/SKILL.md
- claude-md.claude/skills/claude-md/SKILL.md
- code-quality.claude/skills/code-quality/SKILL.md
- data-model.claude/skills/data-model/SKILL.md
- db-migrate.claude/skills/db-migrate/SKILL.md
- debug.claude/skills/debug/SKILL.md
- deploy.claude/skills/deploy/SKILL.md
- dep-update.claude/skills/dep-update/SKILL.md
- disk-cleanup.claude/skills/disk-cleanup/SKILL.md
- eng-lead.claude/skills/eng-lead/SKILL.md
- event-driven.claude/skills/event-driven/SKILL.md
- fullstack-healthcheck.claude/skills/fullstack-healthcheck/SKILL.md
- go-feature.claude/skills/go-feature/SKILL.md
- go-integration-test.claude/skills/go-integration-test/SKILL.md
- go-refactor.claude/skills/go-refactor/SKILL.md
- go-scaffold.claude/skills/go-scaffold/SKILL.md
- incident-response.claude/skills/incident-response/SKILL.md
- interactive-clarify.claude/skills/interactive-clarify/SKILL.md
- observability.claude/skills/observability/SKILL.md
- onboarding.claude/skills/onboarding/SKILL.md
- product-spec.claude/skills/product-spec/SKILL.md
- py-feature.claude/skills/py-feature/SKILL.md
- py-integration-test.claude/skills/py-integration-test/SKILL.md
- py-migrate.claude/skills/py-migrate/SKILL.md
- py-refactor.claude/skills/py-refactor/SKILL.md
- py-scaffold.claude/skills/py-scaffold/SKILL.md
- react-feature.claude/skills/react-feature/SKILL.md
- react-refactor.claude/skills/react-refactor/SKILL.md
- react-scaffold.claude/skills/react-scaffold/SKILL.md
- review-code.claude/skills/review-code/SKILL.md
- security.claude/skills/security/SKILL.md
- system-design.claude/skills/system-design/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

