create-dockerfile
About
This Claude Skill generates production-ready Dockerfiles for Node.js, Python, Go, Rust, and Java applications. It handles base images, dependencies, permissions, and best practices for deployment. Use it when containerizing a new project or preparing an app for cloud deployment without an existing Dockerfile.
Quick Install
Claude Code
Recommendednpx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/create-dockerfileCopy and paste this command in Claude Code to install this skill
Documentation
Create Dockerfile
Write production-ready Dockerfile for general-purpose application projects.
When Use
- Containerizing Node.js, Python, Go, Rust, or Java app
- Making consistent build/runtime environment
- Preparing app for cloud deploy or Docker Compose
- No existing Dockerfile in project
Inputs
- Required: Project language and entry point (e.g.,
npm start,python app.py) - Required: Dependency manifest (package.json, requirements.txt, go.mod, Cargo.toml, pom.xml)
- Optional: Target environment (development or production)
- Optional: Exposed ports
Steps
Step 1: Choose Base Image
| Language | Dev Image | Prod Image | Size |
|---|---|---|---|
| Node.js | node:22-bookworm | node:22-bookworm-slim | ~200MB |
| Python | python:3.12-bookworm | python:3.12-slim-bookworm | ~150MB |
| Go | golang:1.23-bookworm | gcr.io/distroless/static | ~2MB |
| Rust | rust:1.82-bookworm | debian:bookworm-slim | ~80MB |
| Java | eclipse-temurin:21-jdk | eclipse-temurin:21-jre | ~200MB |
Got: Pick slim/distroless variant for production images.
Step 2: Write Dockerfile (by language)
Node.js
FROM node:22-bookworm-slim
RUN groupadd -r appuser && useradd -r -g appuser -m appuser
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
COPY . .
USER appuser
EXPOSE 3000
CMD ["node", "src/index.js"]
Python
FROM python:3.12-slim-bookworm
RUN groupadd -r appuser && useradd -r -g appuser -m appuser
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
USER appuser
EXPOSE 8000
CMD ["python", "app.py"]
Go
FROM golang:1.23-bookworm AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /app/server ./cmd/server
FROM gcr.io/distroless/static
COPY --from=builder /app/server /server
EXPOSE 8080
ENTRYPOINT ["/server"]
Rust
FROM rust:1.82-bookworm AS builder
WORKDIR /src
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs && cargo build --release && rm -rf src
COPY . .
RUN touch src/main.rs && cargo build --release
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /src/target/release/myapp /usr/local/bin/myapp
EXPOSE 8080
ENTRYPOINT ["myapp"]
Java (Maven)
FROM eclipse-temurin:21-jdk AS builder
WORKDIR /src
COPY pom.xml .
RUN mvn dependency:go-offline -B
COPY src ./src
RUN mvn package -DskipTests
FROM eclipse-temurin:21-jre
COPY --from=builder /src/target/*.jar /app/app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
Got: docker build -t myapp . finishes without errors.
If fail: Check base image availability and dependency install commands.
Step 3: ENTRYPOINT vs CMD
| Directive | Purpose | Override |
|---|---|---|
ENTRYPOINT | Fixed executable | Override with --entrypoint |
CMD | Default arguments | Override with trailing args |
| Both | ENTRYPOINT + default args via CMD | Args override CMD only |
Use ENTRYPOINT for compiled binaries with single purpose. Use CMD for interpreted languages where might want docker run myapp bash.
Step 4: Create .dockerignore
.git
.gitignore
node_modules
__pycache__
*.pyc
target/
.env
.env.*
*.md
!README.md
.vscode
.idea
Dockerfile
docker-compose*.yml
Got: Build context drops dev artifacts.
Step 5: Add Non-Root User
Always run as non-root in production:
RUN groupadd -r appuser && useradd -r -g appuser -m appuser
USER appuser
For distroless images, use built-in nonroot user:
FROM gcr.io/distroless/static:nonroot
USER nonroot
Step 6: Build and Verify
docker build -t myapp:latest .
docker run --rm myapp:latest
docker image inspect myapp:latest --format '{{.Size}}'
Got: Container starts, responds on expected port, runs as non-root.
If fail: Check logs with docker logs. Verify WORKDIR, COPY paths, exposed ports.
Checks
-
docker buildfinishes without errors - Container starts and app responds
-
.dockerignoredrops unneeded files - App runs as non-root user
- Dependencies copied before source code (cache efficiency)
- No secrets or
.envfiles baked into image
Pitfalls
- COPY before dependency install: Invalidates dependency cache on every code change. Always copy manifest file first.
- Running as root: Default Docker user is root. Always add non-root user for production.
- Missing .dockerignore: Sending
node_modulesor.gitinto build context wastes time and disk. - Using
latesttag for base images: Pin to specific versions (e.g.,node:22.11.0) for reproducibility. - Forgetting
--no-cache-dir: Pythonpipcaches packages by default, bloating image. - ADD vs COPY: Use
COPYunless need URL download or tar extraction (ADDauto-extracts).
See Also
create-r-dockerfile- R-specific Dockerfile using rocker imagescreate-multistage-dockerfile- multi-stage patterns for minimal production imagesoptimize-docker-build-cache- advanced caching strategiessetup-compose-stack- orchestrate containerized app with other services
GitHub Repository
Related Skills
content-collections
MetaThis skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.
polymarket
MetaThis skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.
creating-opencode-plugins
MetaThis skill helps developers create OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It provides the plugin structure, event API specifications, and implementation patterns for JavaScript/TypeScript modules. Use it when you need to intercept, monitor, or extend the OpenCode AI assistant's lifecycle with custom event-driven logic.
sglang
MetaSGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.
