Back to Skills

create-dockerfile

pjt222
Updated 6 days ago
10 views
17
2
17
View on GitHub
Metaaidesign

About

This Claude Skill generates Dockerfiles for Node.js, Python, Go, Rust, and Java projects, handling base images, dependencies, and configuration. Use it when containerizing an application for the first time or preparing for cloud deployment to ensure a consistent build and runtime environment. It covers essential practices like user permissions, COPY patterns, and the differences between ENTRYPOINT and CMD.

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

造 Dockerfile

書產備 Dockerfile 為標應案。

  • 容器化 Node.js、Python、Go、Rust、Java 應
  • 建一致構/行境
  • 為雲部或 Docker Compose 備應
  • 案中無存 Dockerfile

  • :案語與入點(如 npm startpython app.py
  • :依備(package.json、requirements.txt、go.mod、Cargo.toml、pom.xml)
  • :目境(發或產)
  • :露口

一:擇基像

發像產像
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

得: 產像擇 slim/distroless 變。

二:書 Dockerfile(按語)

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"]

得: docker build -t myapp . 無誤畢。

敗: 察基像可用與依裝令。

三:ENTRYPOINT 與 CMD

ENTRYPOINT定執--entrypoint
CMD默引以尾引覆
ENTRYPOINT + CMD 之默引引僅覆 CMD

編譯單目用 ENTRYPOINT。解譯語可欲 docker run myapp bash 則用 CMD

四:建 .dockerignore

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

得: 構脈除發餘。

五:加非 root 用

產時恆行為非 root:

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

distroless 像用內建 nonroot:

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

六:構與驗

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

得: 容器起、應於期口、非 root 行。

敗:docker logs 察誌。驗 WORKDIR、COPY 路、露口。

  • docker build 無誤畢
  • 容器起應
  • .dockerignore 除餘檔
  • 應為非 root 行
  • 依先複於源(快效)
  • 密或 .env 不入像

  • COPY 先於依裝:碼每變必失依快。先複備
  • 為 root 行:默 Docker 用為 root。產必加非 root
  • 缺 .dockerignorenode_modules.git 入構脈費時費碟
  • 基像用 latest:釘定版(如 node:22.11.0)為重現
  • --no-cache-dir:Python pip 默快包、脹像
  • ADD 與 COPY:用 COPY 除需 URL 下或 tar 解(ADD 自解)

  • create-r-dockerfile - R 專 Dockerfile 用 rocker 像
  • create-multistage-dockerfile - 多段模為最小產像
  • optimize-docker-build-cache - 進快策
  • setup-compose-stack - 以他服調容器化應

GitHub Repository

pjt222/agent-almanac
Path: i18n/wenyan-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