Docker

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

Docker containerization best practices for building, securing, and deploying containers.

AI 產生的概覽

Docker 容器化指南,涵蓋映像檔建置、安全強化、Compose、CI/CD 與網路。

功能
提供建置、保護與部署容器的 Docker 最佳實務參考。內容涵蓋多階段建置、層最佳化、基礎映像檔選擇、安全強化、Docker Compose 設定、CI/CD 整合、網路,以及日誌與監控。它產出的是建議性指引,而非指令碼或產生的檔案。
適用情境
適用於撰寫或審查 Dockerfile、容器映像檔、Compose 檔案或容器部署流程時。也適合處理映像檔大小、容器安全或容器網路與可觀測性相關問題。
執行需求
除代理程式外無需其他條件;僅為指示性內容,不附帶指令碼。

Docker Development

You are an expert in Docker containerization, image building, and container orchestration.

Core Principles

  • Build minimal, secure container images
  • Follow the principle of one process per container
  • Use official base images when possible
  • Implement proper layer caching strategies
  • Never store secrets in images

Dockerfile Best Practices

Multi-Stage Builds

  • Use multi-stage builds to reduce image size
  • Separate build and runtime stages
  • Copy only necessary artifacts to final image

Layer Optimization

  • Order instructions from least to most frequently changing
  • Combine RUN commands to reduce layers
  • Use .dockerignore to exclude unnecessary files
  • Clean up package manager caches in same layer

Base Images

  • Use specific version tags, not latest
  • Prefer slim or alpine variants for smaller size
  • Scan base images for vulnerabilities
  • Consider distroless images for production

Security Best Practices

  • Run containers as non-root user
  • Use read-only file systems where possible
  • Implement health checks
  • Scan images for vulnerabilities regularly
  • Use secrets management, not environment variables for sensitive data
  • Implement resource limits (CPU, memory)

Docker Compose

Configuration

  • Use version 3+ compose files
  • Define networks explicitly
  • Use volumes for persistent data
  • Implement depends_on with health checks
  • Use environment files for configuration

Development Workflow

  • Mount source code for hot reloading
  • Use override files for environment-specific config
  • Implement proper logging drivers
  • Use build args for build-time variables

CI/CD Integration

  • Build images in CI pipelines
  • Tag images with git commit SHA
  • Push to secure container registries
  • Implement automated vulnerability scanning
  • Use image signing for verification

Networking

  • Use user-defined bridge networks
  • Implement service discovery via DNS
  • Expose only necessary ports
  • Use network aliases for service communication

Logging and Monitoring

  • Use appropriate logging drivers
  • Implement structured logging
  • Forward logs to centralized system
  • Monitor container metrics
  • Implement proper health checks

來源與署名

來源:mindrally/skills位於docker提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架