docker-multi-stage

Creates optimized multi-stage Dockerfiles with layer caching, security hardening, and healthchecks.

Updated Jun 13, 2026
One-click install
npx skills add https://github.com/jenreh/project-kit-template --skill docker-multi-stage-jenreh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docker-multi-stage
Source: https://github.com/jenreh/project-kit-template/tree/main/.agents/agent-skills/skills/docker-multi-stage
Command: npx skills add https://github.com/jenreh/project-kit-template --skill docker-multi-stage-jenreh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Dockerfiles that produce small, secure, and fast-building images requires juggling stage structure, base image selection, layer ordering, and security practices. This Skill provides concrete patterns and checklists so containers are built correctly the first time instead of through trial and error. ## Core Features & Use Cases - Multi-Stage Build Patterns: Separates builder and runtime stages so compilers and build tools never ship in production images. - Layer & Cache Optimization: Orders instructions from stable to volatile and uses BuildKit cache mounts for uv, npm, and Go builds. - Security Hardening: Enforces non-root users, pinned image tags, secret mounts, and minimal runtime attack surface. - Use Case: When containerizing a Python FastAPI service, generate a complete two-stage Dockerfile using uv with cache mounts, a non-root user, a healthcheck, and a matching .dockerignore. ## Quick Start Ask the assistant to create an optimized multi-stage Dockerfile for your application stack, for example a Python service using uv or a Node.js app with npm ci.

Frequently Asked Questions about docker-multi-stage

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

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

Use a builder stage to install dependencies with uv sync and cache mounts, then copy only the virtual environment into a slim runtime stage. Pin the base image tag, add a non-root user, and define a HEALTHCHECK for production readiness.

What base image should I use for Docker containers?

Use distroless or alpine for the smallest images, slim variants like python:3.13-slim-bookworm for a balance of size and compatibility, and full bookworm images only in builder stages. Always pin to a specific tag rather than using latest.

How do I speed up Docker builds with layer caching?

Order instructions from least to most frequently changing: system deps, dependency manifests, dependency install, then application code. Use BuildKit cache mounts such as --mount=type=cache,target=/root/.cache/uv to persist package manager caches across builds.

Can I use secrets in a Dockerfile without baking them into the image?

Yes, use BuildKit secret mounts like --mount=type=secret,id=npmrc,target=/root/.npmrc for build-time secrets. Never COPY .env files into the image; pass runtime secrets through environment variables or a secret manager.

Why is my Docker image so large?

Large images usually result from single-stage builds that ship compilers and dev tools, unpinned fat base images, or missing cleanup of package caches. Split builds into stages, combine RUN commands with &&, remove apt lists, and add a .dockerignore file.