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 从公开仓库中收录这些内容。

举报或申请下架