dockerfile-instructions

Author and review multi-stage, multi-architecture Dockerfiles with BuildKit optimization rules.

Updated Apr 11, 2026
One-click install
npx skills add https://github.com/lurodrisilva/personal-skills --skill dockerfile-instructions-lurodrisilva
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dockerfile-instructions
Source: https://github.com/lurodrisilva/personal-skills/tree/main/coding/dockerfile-instructions
Command: npx skills add https://github.com/lurodrisilva/personal-skills --skill dockerfile-instructions-lurodrisilva

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Hand-written Dockerfiles often ship bloated images, leak secrets into layers, rebuild slowly, and fail on ARM machines. This Skill encodes opinionated rules for writing Dockerfiles that are minimal, reproducible, fast to build, and portable across CPU architectures. ## Core Features & Use Cases - Multi-Stage Build Patterns: Enforces named stages, --target builds for test/lint/debug, and dropping the build toolchain from the final image (e.g., Go apps from 800 MB down to 5-20 MB with distroless). - Build-Time and Size Optimization: Covers layer ordering, BuildKit cache mounts, bind mounts, secret mounts, SSH mounts, and CI cache backends (GitHub Actions, registry, local, S3). - Multi-Architecture Builds: Guides buildx setup, QEMU, manifest lists, TARGETPLATFORM/TARGETARCH ARGs, and the FROM --platform=$BUILDPLATFORM cross-compile pattern, plus GitHub Actions and GitLab CI pipeline templates. - Use Case: A developer asks to containerize a Go service for both Apple Silicon laptops and AWS Graviton. The Skill produces a pinned, multi-stage Dockerfile with cache mounts, a non-root distroless final stage, a .dockerignore, and a CI workflow that pushes a multi-arch manifest list. ## Quick Start Ask the AI to write a production Dockerfile for your application, for example: "Write an optimized multi-stage Dockerfile for my Node.js app that builds for both amd64 and arm64."

Frequently Asked Questions about dockerfile-instructions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a multi-stage Dockerfile for a Go application?▼

Use a golang build stage to compile with CGO_ENABLED=0, then copy the binary into a gcr.io/distroless/static-debian12:nonroot final stage with COPY --from=build. This typically reduces the image from 800 MB to 5-20 MB and ships a non-root user by default.

How do I speed up docker build in CI?▼

Order layers from stable to volatile so dependency installs stay cached, and add RUN --mount=type=cache mounts for package manager caches like /go/pkg/mod or /root/.npm. In ephemeral CI runners, persist cache with a backend such as --cache-to type=gha,mode=max on GitHub Actions or a registry cache.

How do I build a Docker image for both amd64 and arm64?▼

Use docker buildx with a docker-container driver builder and run docker buildx build --platform linux/amd64,linux/arm64 --push. Multi-platform images cannot be loaded locally with --load, so test single-platform locally and push the multi-arch manifest list to a registry.

Does BuildKit support passing secrets without leaking them into image layers?▼

Yes, BuildKit supports RUN --mount=type=secret,id=npmrc,target=/root/.npmrc, which mounts the secret only during that step and never writes it to any layer or docker history. Never use --build-arg for secrets since build args persist in image history.

When should I not write a custom Dockerfile?▼

Skip a custom Dockerfile when a first-party reproducible image tool fits your needs, such as ko for Go, jib for Java, pack for Cloud Native Buildpacks, nixpacks, or dotnet publish /t:PublishContainer. Also avoid it when your platform already builds images, like Cloud Run source deploys or Fly.io.

Why does my docker build send gigabytes of context to the daemon?▼

A missing or incomplete .dockerignore causes the entire working tree, including .git, node_modules, and secrets, to be uploaded as build context. Add a .dockerignore covering VCS files, dependency caches, build outputs, and env files to fix speed, size, and cache correctness.