/dd:docker:dockerfilefrom dd:docker
Provides Dockerfile authoring rules covering pinned base images, build context, .dockerignore, layer cache ordering, multi-stage builds, BuildKit secrets, non-root users, and PID 1 signal handling. Useful when writing, editing, or reviewing Dockerfiles or container builds.
Ships in dd:docker. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Four goals, in this order: correct runtime, small image, fast cache, no secrets in layers. A layer is immutable — anything a layer writes ships in the image, even if a later layer deletes it.
latest — the build stops being reproducible the moment upstream moves.node:22.11.0-alpine@sha256:….FROM node:22.11.0-alpine # good — deterministic
FROM node:latest # bad — a different image every rebuild
The daemon receives the whole context directory before the build starts. A large context slows every build, even a fully cached one.
.dockerignore. It cuts upload time and keeps secrets out of the image..git
node_modules
target
dist
*.log
.env
.env.*
**/*.pem
Docker invalidates a layer and every layer after it when its inputs change. So order the file by change frequency: rarely-changed inputs first, source code last.
COPY package.json package-lock.json ./
RUN npm ci # cached until the manifests change
COPY . . # invalidated by every source edit
RUN per logical step with && and \. Clean the package cache inside the same RUN — a separate RUN rm leaves the files in the earlier layer.RUN apt-get update \
&& apt-get install -y --no-install-recommends curl ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY over ADD. ADD also fetches URLs and auto-extracts archives, which makes cache behaviour hard to predict. Use ADD only to extract a local archive.Compile in a stage that holds the SDK, source, and dev dependencies. Copy only the artifact into the runtime stage.
FROM golang:1.23-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /out/app ./cmd/app
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/app /app
USER nonroot
ENTRYPOINT ["/app"]
AS build) and copy by name, not by index.BuildKit runs independent stages in parallel, caches better, and is the only builder that mounts caches and secrets.
Docker Engine 23.0 and later: BuildKit is the default. Plain docker build already uses it. Do not set DOCKER_BUILDKIT=1 — it changes nothing.
Engine 18.09 to 22.x: BuildKit exists but the classic builder is the default. Opt in per build with DOCKER_BUILDKIT=1 docker build …, or set {"features":{"buildkit":true}} in /etc/docker/daemon.json.
Engine below 18.09, or a CI runner you do not control: treat mounts as unavailable. A --mount flag on the classic builder fails the build with a parse error.
docker buildx build uses BuildKit on every version that ships buildx, so prefer it when the engine version is unknown.
Declare the syntax directive on the first line when you use mounts:
# syntax=docker/dockerfile:1
RUN --mount=type=cache,target=/root/.cache/go-build go build ./...
Never put a credential in ARG or ENV. Both persist in the image history, and docker history prints them. Deleting the file in a later layer does not remove it.
Mount the secret instead — it exists only for that RUN:
RUN --mount=type=secret,id=npm_token \
NPM_TOKEN="$(cat /run/secrets/npm_token)" npm ci
docker build --secret id=npm_token,src=./npm_token .
Containers run as root by default. A container escape then starts from root on the host.
RUN addgroup -S app && adduser -S -G app app
USER app
ENTRYPOINT.nonroot user already — use the :nonroot tag and USER nonroot.PID 1 does not get the default signal handlers. If the process ignores SIGTERM, docker stop waits the full timeout and then kills it, so shutdown is never graceful.
ENTRYPOINT ["node", "server.js"] # exec form — node is PID 1
ENTRYPOINT node server.js # shell form — sh is PID 1, node gets nothing
exec:#!/bin/sh
set -e
run-migrations
exec "$@"
tini, or docker run --init) only when the process spawns children and does not reap them..dockerignore excludes .git, dependency dirs, build output, .env, keysCOPYRUN cleans its own caches in the same instructionADD appears only to extract a local archiveARG or ENVUSER is non-root before ENTRYPOINTENTRYPOINT / CMD use exec formWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub napalmpapalam/skills --plugin docker