← 返回
开发者工具

Docker Compose

Define multi-container applications with proper dependency handling, networking, and volume management.
使用正确的依赖处理、网络和卷管理来定义多容器应用。
ivangdavila
开发者工具 clawhub v1.0.0 1 版本 98706.9 Key: 无需
★ 5
Stars
📥 6,541
下载
💾 339
安装
1
版本
#latest

概述

depends_on Ready Condition

  • depends_on: alone only waits for container start—service likely not ready yet
  • Add healthcheck + condition for actual readiness:
  • depends_on:
      db:
        condition: service_healthy
    
  • Without healthcheck defined on target service, service_healthy fails

Healthcheck start_period

healthcheck:
  test: ["CMD", "pg_isready"]
  start_period: 30s
  • start_period: initial grace period—health failures don't count during this time
  • Slow-starting services (databases, Java apps) need adequate start_period
  • Without it, container marked unhealthy before it finishes initializing

Volume Destruction

  • docker compose down preserves volumes
  • docker compose down -v DELETES ALL VOLUMES—data loss
  • -v often added by habit from tutorials—catastrophic in production
  • Named volumes survive down; anonymous volumes deleted on down

Resource Limits in Development

deploy:
  resources:
    limits:
      memory: 512M
  • Set limits during development—catches memory issues early
  • Unlimited container can consume all host memory—kills other processes
  • Copy limits to production config—don't discover limits in prod

.dockerignore

  • Without it: node_modules, .git, secrets copied into image
  • Mirrors .gitignore syntax—create at same level as Dockerfile
  • Large build context = slow builds, large images, potential security issues
  • At minimum: .git, node_modules, .env, *.log, build artifacts

Override File Pattern

  • docker-compose.yml: base config that works everywhere
  • docker-compose.override.yml: auto-loaded, development-specific (mounts, ports)
  • Production: docker compose -f docker-compose.yml -f docker-compose.prod.yml up
  • Keep secrets and environment-specific config in override files, not base

Profiles for Optional Services

services:
  mailhog:
    profiles: [dev]
  • Services with profiles don't start by default—cleaner docker compose up
  • Enable with --profile dev
  • Use for: test databases, debug tools, mock services, admin interfaces

Environment Variable Precedence

  1. Shell environment (highest)
  2. .env file in compose directory
  3. env_file: directive
  4. environment: in compose file (lowest for that var)
    • .env must be exactly .env.env.local not auto-loaded
    • Debug with docker compose config—shows resolved values

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-28 10:57 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 920 📥 185,726
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,349 📥 317,693
developer-tools

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 65 📥 179,834