multi-stage-dockerfile

Creates optimized multi-stage Dockerfiles with layer caching and security best practices.

Updated Aug 2, 2026
One-click install
npx skills add https://github.com/jeje-it/template-projet --skill multi-stage-dockerfile-jeje-it
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: multi-stage-dockerfile
Source: https://github.com/jeje-it/template-projet/tree/main/.agents/skills/multi-stage-dockerfile
Command: npx skills add https://github.com/jeje-it/template-projet --skill multi-stage-dockerfile-jeje-it

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Dockerfiles that produce bloated, insecure images is a common problem. This Skill guides the creation of multi-stage Dockerfiles that separate build and runtime environments, resulting in smaller images with fewer vulnerabilities. ## Core Features & Use Cases - Multi-Stage Structure: Separates builder and runtime stages, copying only necessary artifacts between stages with meaningful stage names. - Layer Optimization: Orders instructions to maximize build cache hits, combines RUN commands, and uses .dockerignore to reduce build context. - Security Hardening: Enforces non-root users, minimal base images, pinned version tags, and removal of build tools from final images. - Use Case: You have a Node.js application whose image is 1.2GB because it ships devDependencies and build tools. Use this Skill to restructure the Dockerfile into builder and runtime stages, cutting the final image to a slim production-only footprint. ## Quick Start Create an optimized multi-stage Dockerfile for my Node.js application following best practices for caching and security.

Frequently Asked Questions about multi-stage-dockerfile

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

FAQPage Schema
How do I create a multi-stage Dockerfile?▼

Define a builder stage with FROM ... AS builder for compilation and dependency installation, then a separate runtime stage that copies only the necessary artifacts using COPY --from=builder. Order stages logically: dependencies, build, test, then runtime.

How to reduce Docker image size with multi-stage builds?▼

Use minimal base images like alpine or distroless for the runtime stage, copy only built artifacts from the builder stage, and remove build tools from the final image. Combining related RUN commands and using .dockerignore further shrinks the result.

What base image should I use for Docker runtime stages?▼

Use official minimal images with exact version tags, such as python:3.11-slim or node:18-alpine. Distroless images work well for runtime stages when your application does not need a shell or package manager.

Why is my Docker build cache not working?▼

Cache breaks when frequently changing instructions like COPY of source code appear before stable ones like dependency installation. Reorder layers from least to most frequently changing so dependency layers are reused across builds.

How do I run a Docker container as a non-root user?▼

Add a USER instruction in the runtime stage specifying a non-root user, and set file ownership during copy with COPY --chown. This prevents the application process from running with root privileges inside the container.