multi-stage-dockerfile — GitHub Copilot skill: setup
This skill guides GitHub Copilot in writing multi-stage Dockerfiles for different languages and frameworks. Use it when the final runtime image should contain fewer build dependencies.
npx skills add github/awesome-copilot --skill multi-stage-dockerfileWhat multi-stage-dockerfile does
The skill guides an agent through separating application builds from runtime execution. A builder stage handles dependency installation and compilation, while a runtime stage receives only the artifacts required to run the app. The suggested flow is dependencies, build, tests, then runtime.
Its guidance covers minimal official images, exact version tags, layer-cache ordering, and .dockerignore. It also calls for removing build tools from the final image, using a non-root USER, setting restrictive permissions, and adding an appropriate HEALTHCHECK.
Install it when Copilot should prepare Dockerfiles across different stacks. For a small app with no separate build step, this skill may add more structure than you need.
What it helps with
- split compilation and runtime into separate stages
- copy only required artifacts into the final image
- order Docker layers for better cache reuse
- remove build packages from the runtime image
- run the container as a non-root user
Example prompts for the agent
- Create a multi-stage Dockerfile for this app with separate dependency, build, test, and runtime stages.
- Review this Dockerfile and improve layer caching, add `.dockerignore`, and remove unnecessary runtime packages.
- Prepare a runtime stage that uses a non-root user and an appropriate `HEALTHCHECK`.
How to install multi-stage-dockerfile
1Skills CLI (Vercel)
npx skills add github/awesome-copilot --skill multi-stage-dockerfile2GitHub CLI
gh skill install github/awesome-copilot multi-stage-dockerfile3Manually: put the files in place
.github/skills/multi-stage-dockerfile/SKILL.md1Skills CLI (Vercel)
npx skills add github/awesome-copilot --skill multi-stage-dockerfile -a claude-code2Manually: put the files in place
~/.claude/skills/multi-stage-dockerfile/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/multi-stage-dockerfile/
Manually: put the files in place
.agents/skills/multi-stage-dockerfile/SKILL.mdFor all projects use ~/.agents/skills/
Manually: put the files in place
.cursor/skills/multi-stage-dockerfile/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
Platform CLI
gemini skills install https://github.com/github/awesome-copilot --path skills/multi-stage-dockerfileManually: put the files in place
.devin/skills/multi-stage-dockerfile/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
From the same set554
The whole set →Similar
Questions about multi-stage-dockerfile
How do I install multi-stage-dockerfile in GitHub Copilot?
Run npx skills add github/awesome-copilot --skill multi-stage-dockerfile. The skill file is then available at .github/skills/multi-stage-dockerfile/SKILL.md.
What does multi-stage-dockerfile do?
It guides the agent in separating build steps from runtime steps and copying only required artifacts into the final Docker image. The guidance also covers layer caching and basic container security.
Which languages does multi-stage-dockerfile support?
The skill is intended for applications written in different languages and frameworks. Base-image choices still depend on application compatibility, especially with Alpine or distroless images.
Source text
SKILL.md · MIT
--- name: multi-stage-dockerfile description: 'Create optimized multi-stage Dockerfiles for any language or framework' --- 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
© github · MIT · github/awesome-copilot