Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)40k · #7301

multi-stage-dockerfile

Skill này làm gì

AI agent này giúp tạo Dockerfile hiệu quả để chạy chương trình trong container. Nó chia quy trình thành nhiều giai đoạn để kết quả cuối cùng nhỏ hơn, an toàn hơn và nhanh hơn.

Khi nào nên dùng

  • ✓Khi bạn muốn tạo một 'gói' để chạy chương trình ở bất cứ đâu.
  • ✓Khi bạn muốn làm 'gói' của chương trình nhỏ nhất có thể.
  • ✓Khi bạn muốn làm 'gói' an toàn hơn trước các cuộc tấn công.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/multi-stage-dockerfile/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tạo một Dockerfile tối ưu cho ứng dụng Node.js dùng React.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ dùng kỹ thuật 'multi-stage builds': một giai đoạn xây dựng chương trình, và một giai đoạn khác, gọn hơn, chỉ chạy nó. Nhờ vậy, chỉ những thứ thiết yếu mới nằm trong kết quả cuối cùng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

Dockerfile là gì?

Đó là file văn bản chứa các chỉ dẫn để Docker tạo một môi trường cô lập (container) nơi chương trình của bạn có thể chạy.

Vì sao “multi-stage” tốt hơn?

Vì nó tách công cụ “xây dựng” chương trình khỏi môi trường chạy, cho ra container cuối cùng nhỏ hơn nhiều và an toàn hơn.

“Container” là gì?

Đó giống như những chiếc hộp cô lập chứa mọi thứ chương trình cần để chạy, giúp dễ dàng chạy trên các máy tính khác nhau.

Chi tiết

Mô tả gốc của tác giả

Create optimized multi-stage Dockerfiles for any language or framework

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7301
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự