Skip to content
Skillpedia
Deploy & cloud (DevOps)40k · #5244

multi-stage-dockerfile

Lets your agent create optimized Docker files. It uses multiple stages to make images smaller and faster.

What it does

This AI agent helps create efficient Dockerfiles for running programs in containers. It organizes the process into stages to ensure the final result is smaller, more secure, and faster.

When to use it

  • ✓When you want to create a 'package' to run your program anywhere.
  • ✓To make your program's 'package' as small as possible.
  • ✓To make your program's 'package' more secure against attacks.

Example of what to ask your AI

“Create an optimized Dockerfile for a Node.js application using React.”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/github/awesome-copilot/blob/main/skills/multi-stage-dockerfile/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/multi-stage-dockerfile/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

It uses a technique called 'multi-stage builds', where one stage builds the program and another, cleaner stage, just runs it. This ensures only the essentials go into the final result.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add github/awesome-copilot --skill multi-stage-dockerfile

Or download just the file:

curl -L https://raw.githubusercontent.com/github/awesome-copilot/main/skills/multi-stage-dockerfile/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Your goal is to help me create efficient multi-stage Dockerfiles that follow best practices, resulting in smaller, more secure container images.

Multi-Stage Structure

  • Use a builder stage for compilation, dependency installation, and other build-time operations
  • Use a separate runtime stage that only includes what's needed to run the application
  • Copy only the necessary artifacts from the builder stage to the runtime stage
  • Use meaningful stage names with the AS keyword (e.g., FROM node:18 AS builder)
  • Place stages in logical order: dependencies → build → test → runtime

Base Images

  • Start with official, minimal base images when possible
  • Specify exact version tags to ensure reproducible builds (e.g., python:3.11-slim not just python)
  • Consider distroless images for runtime stages where appropriate
  • Use Alpine-based images for smaller footprints when compatible with your application
  • Ensure the runtime image has the minimal necessary dependencies

Layer Optimization

  • Organize commands to maximize layer caching
  • Place commands that change frequently (like code changes) after commands that change less frequently (like dependency installation)
  • Use .dockerignore to prevent unnecessary files from being included in the build context
  • Combine related RUN commands with && to reduce layer count
  • Consider using COPY --chown to set permissions in one step

Security Practices

  • Avoid running containers as root - use USER instruction to specify a non-root user
  • Remove build tools and unnecessary packages from the final image
  • Scan the final image for vulnerabilities
  • Set restrictive file permissions
  • Use multi-stage builds to avoid including build secrets in the final image

Performance Considerations

  • Use build arguments for configuration that might change between environments
  • Leverage build cache efficiently by ordering layers from least to most frequently changing
  • Consider parallelization in build steps when possible
  • Set appropriate environment variables like NODE_ENV=production to optimize runtime behavior
  • Use appropriate healthchecks for the application type with the HEALTHCHECK instruction
FAQ

What is a Dockerfile?

It's a text file with instructions for Docker to create an isolated environment (container) where your program can run.

Why is 'multi-stage' better?

Because it separates the program 'building' tools from the 'runtime' environment, resulting in a much smaller and more secure final container.

What are 'containers'?

They are like isolated boxes that contain everything a program needs to run, making it easy to run on different computers.

Details

Original description by the author

Create optimized multi-stage Dockerfiles for any language or framework

repo: github/awesome-copilot

Popularity

GitHub stars
40k
Ranking position
#5244
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills