New to Claude Skills? Learn how to install them →

github on GitHub

Multi-Stage Dockerfile

OfficialFree

Create optimized multi-stage Dockerfiles efficiently.

by github37.7k stars on github/awesome-copilot
1 views
Updated Aug 10, 2026
Get this skill

Free · Opens the source repo

What Multi-Stage Dockerfile does

The Multi-Stage Dockerfile skill is designed to assist developers in creating efficient and optimized multi-stage Dockerfiles that adhere to best practices. This skill emphasizes the importance of structuring Dockerfiles to minimize the size and improve the security of container images. By leveraging a builder stage for compilation and a separate runtime stage for execution, users can ensure that only the necessary components are included in the final image. This results in smaller, more secure containers that are quicker to deploy and easier to manage.

The skill provides detailed guidance on selecting appropriate base images, advocating for the use of official, minimal images with specific version tags to promote reproducibility. It also highlights the advantages of using Alpine-based and distroless images where applicable. Users are encouraged to optimize their Dockerfile layers by organizing commands effectively, utilizing .dockerignore files, and combining commands to reduce the overall layer count. These practices not only lead to smaller images but also enhance build performance through efficient layer caching.

Security is a key focus of this skill, with recommendations to avoid running containers as root, remove unnecessary build tools, and scan images for vulnerabilities. By following these guidelines, developers can create Docker images that are not only efficient but also secure against potential threats. The skill also touches on performance considerations, such as using build arguments and health checks, ensuring that the final container is optimized for production use.

This skill is particularly useful for developers and DevOps engineers who are looking to streamline their containerization processes and adopt best practices in Docker image creation. Whether you are building applications in Node.js, Python, or any other language, this skill provides the foundational knowledge needed to create robust multi-stage Dockerfiles.

When to use it

Use this skill when you need to create Dockerfiles that are optimized for size and security, especially for production environments.

When not to use it

This skill may not be suitable for users who are unfamiliar with Docker concepts or those who require a simple, single-stage Dockerfile setup.

What you can build with it

Building a Node.js Application

When developing a Node.js application, use this skill to create a multi-stage Dockerfile that compiles your app in a builder stage and runs it in a minimal runtime environment.

Optimizing Python Deployments

For Python applications, this skill guides you in creating Dockerfiles that use slim base images and only include runtime dependencies, ensuring faster deployment and lower resource usage.

Securing Container Images

Utilize this skill to implement best practices in Dockerfile security, such as running as a non-root user and scanning images for vulnerabilities, to protect your applications in production.

How to install Multi-Stage Dockerfile

View source

1. Install with the skills CLI

npx skills add github/awesome-copilot/multi-stage-dockerfile --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by 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

Frequently asked questions about Multi-Stage Dockerfile

Similar skills