Back to Skills

create-dockerfile

pjt222
Updated 2 days ago
4 views
17
2
17
View on GitHub
Metaaidesign

About

This Claude Skill generates production-ready Dockerfiles for Node.js, Python, Go, Rust, and Java applications. It handles core concerns like base images, dependencies, permissions, and entrypoint configuration. Use it when starting containerization for a project or preparing an app for cloud deployment where no Dockerfile exists.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/create-dockerfile

Copy and paste this command in Claude Code to install this skill

Documentation

Create Dockerfile

Prod-ready Dockerfile for general-purpose apps.

Use When

  • Containerize Node/Python/Go/Rust/Java app
  • Consistent build/runtime env
  • Cloud deploy / Docker Compose prep
  • No existing Dockerfile

In

  • Required: Lang + entry (npm start, python app.py)
  • Required: Dep manifest (package.json, requirements.txt, go.mod, Cargo.toml, pom.xml)
  • Optional: Target env (dev/prod)
  • Optional: Exposed ports

Do

Step 1: Base Image

LangDev ImgProd ImgSize
Node.jsnode:22-bookwormnode:22-bookworm-slim~200MB
Pythonpython:3.12-bookwormpython:3.12-slim-bookworm~150MB
Gogolang:1.23-bookwormgcr.io/distroless/static~2MB
Rustrust:1.82-bookwormdebian:bookworm-slim~80MB
Javaeclipse-temurin:21-jdkeclipse-temurin:21-jre~200MB

Got: Slim/distroless for prod.

Step 2: Write Dockerfile (per lang)

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 . → no err.

If err: Check base img avail + dep install cmds.

Step 3: ENTRYPOINT vs CMD

DirectivePurposeOverride
ENTRYPOINTFixed exec--entrypoint
CMDDefault argsTrailing args
BothENTRYPOINT + def args via CMDArgs override CMD only

ENTRYPOINT → compiled single-purpose. CMD → interpreted (want docker run myapp bash).

Step 4: .dockerignore

.git
.gitignore
node_modules
__pycache__
*.pyc
target/
.env
.env.*
*.md
!README.md
.vscode
.idea
Dockerfile
docker-compose*.yml

Got: Build ctx no dev artifacts.

Step 5: Non-Root User

Always non-root prod:

RUN groupadd -r appuser && useradd -r -g appuser -m appuser
USER appuser

Distroless:

FROM gcr.io/distroless/static:nonroot
USER nonroot

Step 6: Build + Verify

docker build -t myapp:latest .
docker run --rm myapp:latest
docker image inspect myapp:latest --format '{{.Size}}'

Got: Container starts, port responds, non-root.

If err: docker logs. Check WORKDIR, COPY paths, ports.

Check

  • docker build no err
  • Container starts + responds
  • .dockerignore excludes junk
  • App non-root
  • Deps copied before src (cache)
  • No secrets / .env in img

Traps

  • COPY before dep install: Invalidates cache on code change. Manifest first.
  • Root user: Def Docker = root. Add non-root prod.
  • No .dockerignore: node_modules / .git in ctx → waste.
  • latest tag: Pin ver (node:22.11.0) → repro.
  • No --no-cache-dir: pip caches → img bloat.
  • ADD vs COPY: COPY unless URL / tar (ADD auto-extracts).

  • create-r-dockerfile — R-specific via rocker
  • create-multistage-dockerfile — multi-stage min prod imgs
  • optimize-docker-build-cache — cache strategies
  • setup-compose-stack — orchestrate w/ other svcs

GitHub Repository

pjt222/agent-almanac
Path: i18n/caveman-ultra/skills/create-dockerfile
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

content-collections

Meta

This 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.

View skill

polymarket

Meta

This 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.

View skill

creating-opencode-plugins

Meta

This 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.

View skill

sglang

Meta

SGLang 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.

View skill