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

multi-stage-dockerfile

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.

Skill link

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

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

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.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

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

5 new skills a week. 1 minute to read.

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.

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
#7301
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills