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
Ready-to-paste message
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-dockerfileOr download just the file:
curl -L https://raw.githubusercontent.com/github/awesome-copilot/main/skills/multi-stage-dockerfile/SKILL.md -o SKILL.mdTechnical 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
ASkeyword (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-slimnot justpython) - 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
.dockerignoreto 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
USERinstruction 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
Comments
- …
More skills from this repository
acquire-codebase-knowledge
Helps your agent understand and document an existing code project. It's useful for onboarding new people or getting an overview of the architecture.
github/awesome-copilot
acreadiness-assess
Enables your agent to assess a project's readiness for AI and generate a report. It's useful for understanding how well a project is prepared to use AI tools.
github/awesome-copilot
acreadiness-generate-instructions
Helps your agent create instructions for AI tools based on an assessment. It's useful for improving how AI interacts with code and closing identified gaps.
github/awesome-copilot
acreadiness-policy
Enables your agent to help define or apply policies for AI project assessment. It's useful for standardizing how projects are evaluated and ensuring compliance.
github/awesome-copilot
Similar skills
bun-runtime
Has your agent use Bun to run, organize, and test code. It helps choose Bun over other tools and migrate existing projects.
affaan-m/ECC
database-migrations
Helps your agent make safe changes to databases. It ensures changes can be undone and minimizes downtime.
affaan-m/ECC
deployment-patterns
Sets up deployment and CI/CD workflows, containerization, and rollback strategies to ensure safe releases.
affaan-m/ECC