This skill may not reflect the latest upstream change
Next.js Releases update on 2026-11-09 may affect this skill Last checked Nov 26, 2026.
docker
We earn commissions when you shop through the links below.
Detect project stack and generate production-ready multi-stage Dockerfiles with compose services, .dockerignore, non-root users, health checks, layer caching, and optional dev hot-reload profiles
Install this skill
No account required. Pick your tool, or use the command that detects it for you.
Run in your terminal. It detects your AI tool.
npx @skills-hub-ai/cli install dockerManual setup by platform
Claude Code
~/.claude/skills/docker/SKILL.md
Signing
SignedSLSA L2- Signed by
- skills-hub.ai distributor
- Method
- Distributor-signed by skills-hub.aiSigned with the skills-hub.ai Ed25519 distributor key over this exact slug, version and content. Check it with `npx @skills-hub-ai/cli verify`.
- Key
- skills-hub-ed25519-2026-11
- Signed
Instructions
You are in AUTONOMOUS MODE. Do NOT ask questions. Do NOT pause for confirmation.
Execute every phase below in sequence, making decisions based on what you find.
PHASE 0 — INPUT
$ARGUMENTS may contain:
--compose— also generate docker-compose.yml (default: auto-detect need)--dev— include development compose profile with hot reload--prod— optimize for production (smaller image, no dev deps)--registry <url>— target container registry (default: ghcr.io)- A specific service name to Dockerize (for monorepos)
--slim— use Alpine/distroless base images for minimal size
If no arguments, generate both Dockerfile and docker-compose.yml if the project has dependencies (database, cache, etc.).
PHASE 1 — STACK DETECTION
Detect the application stack by reading manifest files:
Node.js:
- Read
package.jsonfor:engines.node,scripts.start,scripts.build, framework - Lock file determines package manager:
package-lock.json(npm),yarn.lock(yarn),pnpm-lock.yaml(pnpm) - Framework detection: Next.js (
next.config.*), Fastify, Express, NestJS, Remix, Astro - Check for
tsconfig.json— TypeScript build step needed
Python:
- Read
pyproject.toml,requirements.txt,Pipfile,setup.py - Framework: Django (
manage.py), Flask, FastAPI (uvicorn/gunicorn) - Python version from
.python-version,pyproject.toml, orruntime.txt
Go:
- Read
go.modfor module name and Go version - Check for
cmd/main.goormain.goentry point - Static binary — ideal for scratch/distroless final stage
Rust:
- Read
Cargo.tomlfor binary name - Static binary with musl target — ideal for scratch/distroless
Java:
- Read
pom.xml(Maven) orbuild.gradle(Gradle) - Check for Spring Boot, Quarkus, Micronaut
- JRE-only final stage
Ruby:
- Read
Gemfilefor Ruby version and framework (Rails, Sinatra) - Check for
config.ru(Rack app)
Also detect dependencies that need compose services:
- Database: Prisma schema, SQLAlchemy, GORM, ActiveRecord, TypeORM — note the DB engine
- Cache: Redis references in config/code
- Message queue: RabbitMQ, Kafka references
- Search: Elasticsearch references
- Object storage: S3/MinIO references
PHASE 2 — GENERATE DOCKERFILE
Create a multi-stage Dockerfile following these principles:
Stage 1 — Dependencies (deps or builder):
- Use specific version tags, never
latest(e.g.,node:22-alpine,python:3.12-slim) - Copy lock file BEFORE source code (layer caching optimization)
- Install only production dependencies first
- Use
--mount=type=cachefor package manager caches where supported
Stage 2 — Build (if applicable):
- Copy source code after dependency install
- Run build command (
npm run build,go build,cargo build --release) - For compiled languages, produce a static binary if possible
Stage 3 — Production:
- Use smallest appropriate base image:
- Node.js:
node:22-alpine(ordistrolessif--slim) - Python:
python:3.12-slim - Go:
gcr.io/distroless/static-debian12orscratch - Rust:
gcr.io/distroless/cc-debian12orscratch - Java:
eclipse-temurin:21-jre-alpine - Ruby:
ruby:3.3-slim
- Node.js:
- Copy only built artifacts and production deps from previous stages
- Set
WORKDIR /app
Security hardening (always apply):
- Create non-root user with fixed UID/GID 1001
USER appuserbefore CMD- No
apt-get upgrade— pin base image version instead
Health check (always include):
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3- Node.js:
wget --no-verbose --tries=1 --spider http://localhost:${PORT}/health || exit 1 - Python:
curl -f http://localhost:${PORT}/health || exit 1 - Go: built-in health endpoint check
- For apps without a health endpoint, note that one should be created
Labels (OCI standard):
LABEL org.opencontainers.image.source="https://github.com/OWNER/REPO"
LABEL org.opencontainers.image.description="Description"
Environment:
- Set
NODE_ENV=productionor equivalent - Set default
PORTandEXPOSEit - Never bake secrets into the image
PHASE 3 — GENERATE .dockerignore
Create .dockerignore to minimize build context. Always exclude:
.gitdirectory- IDE config (
.vscode,.idea) - Test coverage output (
coverage,.nyc_output,.pytest_cache) - Environment files (
.env*) - Build artifacts that will be regenerated in the container
node_modules(rebuilt inside container)- Documentation files (
*.md)
Adjust patterns based on detected stack.
PHASE 4 — GENERATE DOCKER COMPOSE
Create docker-compose.yml if the application has external dependencies or --compose is set.
Structure requirements:
- Omit
version:field (Docker Compose V2+ does not need it) - Use
depends_onwithcondition: service_healthyfor startup ordering - Use named volumes for data persistence
- Use a named bridge network for service communication
- Use environment variable references
${VAR:-default}for configurable values - Set
restart: unless-stoppedon all services
Database services: Include proper health checks:
- PostgreSQL:
pg_isready -U postgres - MySQL:
mysqladmin ping -h localhost - MongoDB:
mongosh --eval "db.runCommand('ping')"
Cache services: Include memory limits and eviction policy configuration.
Development profile (if --dev):
Create a docker-compose.dev.yml override with:
- Source code mounted as volume for hot reload
- Development build target in Dockerfile
- Debug ports exposed
NODE_ENV=developmentor equivalent
PHASE 5 — VALIDATION
After generating files, verify:
- Layer ordering — dependency install comes before source copy
- No secrets — no hardcoded passwords, API keys, or tokens in Dockerfile or compose
- Port consistency — EXPOSE matches the app's actual listen port
- Health check — endpoint referenced in HEALTHCHECK actually exists (or note to create it)
- Base image tags — all pinned to specific versions, no
latest - Non-root user — USER directive is present and set before CMD
SELF-HEALING VALIDATION (max 2 iterations)
After completing deployment/infrastructure changes, validate:
- Verify all generated files are syntactically valid (YAML, JSON, HCL, Dockerfile).
- Run validation commands if available (terraform validate, docker build --check, kubectl dry-run).
- Verify no secrets, credentials, or sensitive values are hardcoded.
- If validation fails, diagnose and fix the specific syntax or config error.
- Repeat up to 2 iterations.
IF STILL FAILING after 2 iterations:
- Document what failed and the exact error
- Include partial output if available
OUTPUT
Print a summary:
## Docker Setup Complete
### Files Created
- Dockerfile — Multi-stage build ({base image}, {final size estimate})
- .dockerignore — {N} patterns to minimize build context
- docker-compose.yml — Services: {list}
- docker-compose.dev.yml — Development overrides (if generated)
### Build Commands
- Production: docker compose up --build -d
- Development: docker compose -f docker-compose.yml -f docker-compose.dev.yml up
- Image only: docker build -t {name}:latest .
### Image Details
- Base: {base image}
- Estimated size: {size estimate}
- User: appuser (non-root, UID 1001)
- Health check: {endpoint}
- Exposed port: {port}
### Services
| Service | Image | Port | Volume |
|---------|-------|------|--------|
| app | built | {port} | -- |
| db | postgres:16 | 5432 | db-data |
NEXT STEPS
- Build and test locally:
docker compose up --build - Add a
/healthendpoint to the application if one does not exist - Configure CI/CD to build and push the Docker image (run
deploy/github-actions) - Set real database credentials via environment variables or secrets manager (run
deploy/secrets)
SELF-EVOLUTION TELEMETRY
After producing output, record execution metadata for the /evolve pipeline.
Check if a project memory directory exists:
- Look for the project path in
~/.claude/projects/ - If found, append to
skill-telemetry.mdin that memory directory
Entry format:
### /docker — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}
Only log if the memory directory exists. Skip silently if not found.
Keep entries concise — /evolve will parse these for skill improvement signals.
DO NOT
- Do NOT use
latesttag for base images — pin to specific versions - Do NOT run containers as root — always create and switch to a non-root user
- Do NOT copy
.envfiles into the image — use environment variables at runtime - Do NOT install development dependencies in the production stage
- Do NOT use
ADDwhenCOPYsuffices (ADD has implicit tar extraction and URL fetch) - Do NOT include
apt-get upgrade— use a pinned base image instead - Do NOT leave package manager caches in final image (use
--mount=type=cacheor clean up) - Do NOT overwrite an existing Dockerfile without reading it first and preserving custom configuration
- Do NOT hardcode database passwords — use environment variable references
Security
Reviews (0)
Related skills
Browse all →More from Skills Hub
View source →More Deploy skills
Browse category →Frequently asked questions about docker
What does the docker skill do?
Detect project stack and generate production-ready multi-stage Dockerfiles with compose services, .dockerignore, non-root users, health checks, layer caching, and optional dev hot-reload profiles It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the docker skill?
Run `npx @skills-hub-ai/cli install docker` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/docker/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does docker work with?
docker runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the docker skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use docker after installing it?
In Claude Code, type `/docker` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the docker skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.