本文へスキップ
Skillpedia
デプロイとクラウド(DevOps)40k · #7301

multi-stage-dockerfile

できること

このAIエージェントは、コンテナでプログラムを実行するための効率的なDockerfileの作成を支援します。工程を複数のステージに分けることで、最終的な成果物がより小さく、安全で、高速になるようにします。

使う場面

  • ✓プログラムをどこでも実行できる「パッケージ」を作成したいとき。
  • ✓プログラムの「パッケージ」をできるだけ小さくしたいとき。
  • ✓プログラムの「パッケージ」を攻撃からより安全に守りたいとき。

スキルのリンク

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

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/github/awesome-copilot/blob/main/skills/multi-stage-dockerfile/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“Reactを使用したNode.jsアプリケーション用に、最適化されたDockerfileを作成してください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

「マルチステージビルド」という手法を使います。ひとつのステージでプログラムをビルドし、別のよりクリーンなステージでそれを実行するだけにします。これにより、必要なものだけが最終的な成果物に含まれるようになります。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)を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
よくある質問

Dockerfileとは何ですか?

Dockerに対して、プログラムを実行するための隔離された環境(コンテナ)を作成する指示を書いたテキストファイルです。

「マルチステージ」の方がよいのはなぜですか?

プログラムをビルドするためのツールと、実行環境を分離するためです。その結果、最終的なコンテナがずっと小さく、より安全になります。

「コンテナ」とは何ですか?

プログラムの実行に必要なものをすべて収めた、隔離された箱のようなものです。これにより、さまざまなコンピュータで簡単に実行できます。

詳細

作者による元の説明

Create optimized multi-stage Dockerfiles for any language or framework

repo: github/awesome-copilot

人気

GitHubのスター
40k
ランキング
#7301
ライセンス
MIT
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル