Docker Compose执行失败:Compose文件无效报错求助
The error you're seeing is because Docker Compose version 3 does not support the object syntax for depends_on (with condition keys). In version 3, the depends_on field expects a simple array of service names instead.
What's Wrong in Your Config
Your current depends_on section uses an object format that's incompatible with version 3:
depends_on: mongo: condition: service_started
Corrected Config
Change the depends_on section to an array of service names to resolve the validation error:
pisignage-server: image: pisignage/pisignage-server:latest restart: unless-stopped ports: - 3000:3000 volumes: - media:/media - data:/data depends_on: - mongo # This is the correct array syntax for version 3
Bonus: Waiting for MongoDB to Be Fully Ready
Note that depends_on only waits for the MongoDB container to start—it doesn't verify that the MongoDB service inside is fully ready to accept connections. If you need to ensure pisignage-server starts only after MongoDB is operational, you can use a newer Compose format (version 3.8+) with health checks:
- Update your Compose file version to
3.8:
version: '3.8'
- Add a health check to the mongo service:
mongo: image: mongo:4.2.8 restart: unless-stopped ports: - 27017:27017 volumes: - mongodb:/data/db - mongodb_config:/data/configdb healthcheck: test: ["CMD", "mongo", "--eval", "db.adminCommand('ping')"] interval: 10s timeout: 5s retries: 5
- Use conditional dependency syntax:
pisignage-server: # ... other config ... depends_on: mongo: condition: service_healthy
This ensures pisignage-server only starts once MongoDB passes its health check.
内容的提问来源于stack exchange,提问作者Sasa Blagojevic

