Dockerize and Deploy
Containerize a repo and produce a deployment setup, one phase at a time.
Workflow
1. Audit
Identify runtime, services, datastores, build step, existing Docker files, and env vars. Propose phases before writing.
2. Phases
- Dockerfile — multi-stage: builder installs/compiles, runtime copies artifacts only, non-root user, pinned base image (e.g.
node:20.11-alpine), .dockerignore excludes node_modules/.env/.git.
- docker-compose — dev stack: source mounts for hot reload, debug ports, named volumes.
- Production compose (
docker-compose.prod.yml) — no source mounts, restart: unless-stopped, healthchecks, explicit volumes, mem_limit/cpus limits. See REFERENCE.md.
- Pre-flight — copy
scripts/preflight.sh into the project; validates env vars, Docker, port conflicts, DB reachability, dry-run build. Run: bash scripts/preflight.sh.
- Deploy —
scripts/deploy.sh: run preflight.sh (abort on fail) → pull/build image → run migrations → rolling restart → health-check → print status.
Merge or skip phases for simple repos.
3. Verify after each phase
docker build -t app:test . # Dockerfile compiles
docker compose config # compose files are valid YAML
docker compose up -d && docker compose ps # services start healthy
bash scripts/preflight.sh # pre-flight passes
Guardrails
- Never embed secrets in Docker/compose files.
- Always run containers as a non-root user.
- No
latest image tags in production — pin versions.
- DB volumes: named volumes only, never host bind mounts.
- No
.env.example? Create one first.
References
- REFERENCE.md — volume/healthcheck patterns, resource limits, multi-stage examples by runtime, rolling deploy strategies.
1---2name: dockerize-and-deploy3description: Dockerizes a repo — Dockerfile, docker-compose with volumes, and a preflight script. Use to containerize an app, add Docker support, write a deployment pipeline, set up docker-compose, configure volumes, or deploy to production with Docker.4---56# Dockerize and Deploy78Containerize a repo and produce a deployment setup, one phase at a time.910## Workflow1112### 1. Audit13Identify runtime, services, datastores, build step, existing Docker files, and env vars. Propose phases before writing.1415### 2. Phases161. **Dockerfile** — multi-stage: builder installs/compiles, runtime copies artifacts only, non-root user, pinned base image (e.g. `node:20.11-alpine`), `.dockerignore` excludes `node_modules`/`.env`/`.git`.172. **docker-compose** — dev stack: source mounts for hot reload, debug ports, named volumes.183. **Production compose** (`docker-compose.prod.yml`) — no source mounts, `restart: unless-stopped`, healthchecks, explicit volumes, `mem_limit`/`cpus` limits. See [REFERENCE.md](REFERENCE.md).194. **Pre-flight** — copy `scripts/preflight.sh` into the project; validates env vars, Docker, port conflicts, DB reachability, dry-run build. Run: `bash scripts/preflight.sh`.205. **Deploy** — `scripts/deploy.sh`: run `preflight.sh` (abort on fail) → pull/build image → run migrations → rolling restart → health-check → print status.2122Merge or skip phases for simple repos.2324### 3. Verify after each phase2526```bash27docker build -t app:test . # Dockerfile compiles28docker compose config # compose files are valid YAML29docker compose up -d && docker compose ps # services start healthy30bash scripts/preflight.sh # pre-flight passes31```3233## Guardrails3435- Never embed secrets in Docker/compose files.36- Always run containers as a non-root user.37- No `latest` image tags in production — pin versions.38- DB volumes: named volumes only, never host bind mounts.39- No `.env.example`? Create one first.4041## References4243- [REFERENCE.md](REFERENCE.md) — volume/healthcheck patterns, resource limits, multi-stage examples by runtime, rolling deploy strategies.