关于
This Claude Skill generates production-ready Dockerfiles for Node.js, Python, Go, Rust, and Java applications. It handles best practices like base image selection, dependency management, user permissions, and multi-stage builds. Use it when containerizing a new project or preparing an app for cloud deployment where no Dockerfile exists.
快速安装
Claude Code
推荐npx 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-dockerfile在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Create Dockerfile
Write a production-ready Dockerfile for general-purpose application projects.
When to Use
- Containerizing a Node.js, Python, Go, Rust, or Java application
- Creating a consistent build/runtime environment
- Preparing an application for cloud deployment or Docker Compose
- No existing Dockerfile in the 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
Procedure
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: Select the 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 . completes without errors.
If fail: Check base image availability and dependency installation 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 a single purpose. Use CMD for interpreted languages where you 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 excludes development 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 the 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 the expected port, runs as non-root.
If fail: Check logs with docker logs. Verify WORKDIR, COPY paths, and exposed ports.
Validation
-
docker buildcompletes without errors - Container starts and application responds
-
.dockerignoreexcludes unnecessary files - Application runs as non-root user
- Dependencies are copied before source code (cache efficiency)
- No secrets or
.envfiles baked into the image
Pitfalls
- COPY before dependency install: Invalidates the dependency cache on every code change. Always copy the manifest file first.
- Running as root: Default Docker user is root. Always add a non-root user for production.
- Missing .dockerignore: Sending
node_modulesor.gitinto the 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 the image. - ADD vs COPY: Use
COPYunless you need URL download or tar extraction (ADDauto-extracts).
Related Skills
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 the containerized app with other services
GitHub 仓库
Frequently asked questions
What is the create-dockerfile skill?
create-dockerfile is a Claude Skill by pjt222. Skills package instructions and resources that Claude loads on demand, so Claude can perform create-dockerfile-related tasks without extra prompting.
How do I install create-dockerfile?
Use the install commands on this page: add create-dockerfile to Claude Code as a plugin, or clone its repository into your skills directory, then restart Claude so it picks up the skill.
What category does create-dockerfile belong to?
create-dockerfile is in the Meta category, tagged ai and design.
Is create-dockerfile free to use?
Yes. create-dockerfile is listed on AIMCP and free to install. It runs inside Claude, so no separate service account is required to use the skill itself.
相关推荐技能
Content Collections 是一个 TypeScript 优先的构建工具,可将本地 Markdown/MDX 文件转换为类型安全的数据集合。它专为构建博客、文档站和内容密集型 Vite+React 应用而设计,提供基于 Zod 的自动模式验证。该工具涵盖从 Vite 插件配置、MDX 编译到生产环境部署的完整工作流。
这个Claude Skill为开发者提供完整的Polymarket预测市场开发支持,涵盖API调用、交易执行和市场数据分析。关键特性包括实时WebSocket数据流,可监控实时交易、订单和市场动态。开发者可用它构建预测市场应用、实施交易策略并集成实时市场预测功能。
该Skill帮助开发者创建OpenCode插件,用于接入命令、文件、LSP等25+种事件。它提供了插件结构、事件API规范和JavaScript/TypeScript实现模式,适合需要拦截操作、扩展功能或自定义事件处理的场景。开发者可通过它快速构建响应式模块来增强OpenCode AI助手的能力。
SGLang是一个专为LLM设计的高性能推理框架,特别适用于需要结构化输出的场景。它通过RadixAttention前缀缓存技术,在处理JSON、正则表达式、工具调用等具有重复前缀的复杂工作流时,能实现极速生成。如果你正在构建智能体或多轮对话系统,并追求远超vLLM的推理性能,SGLang是理想选择。
