Docker 生產環境部署

Docker 2025-01-02T04:00:00.000Z

Docker 生產環境部署

Docker 生產環境部署需要考慮安全性、效能、監控等多個面向。

容器安全

RUN adduser --disabled-password appuser
USER appuser
docker run --read-only --tmpfs /tmp nginx

資源限制

docker run -d \
  --cpus=1.5 \
  --memory=512m \
  --memory-swap=512m \
  nginx

健康檢查

HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
  CMD curl -f http://localhost/health || exit 1

生產檢查清單

  • 使用特定版本標籤(非 latest)
  • 設定資源限制
  • 啟用健康檢查
  • 設定日誌輪替
  • 使用非 root 使用者