docker
config_error
ai_generated
true
ERROR: Circular dependency detected: service1 depends on service2 which depends on service1
ID: docker/compose-service-dependency-cycle
95%Fix Rate
90%Confidence
1Evidence
2023-11-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Docker Compose v2.0.0 | active | — | — | — |
| Docker Compose v2.20.0 | active | — | — | — |
| Docker Compose v2.24.0 | active | — | — | — |
Root Cause
In a docker-compose.yml file, services have a circular dependency chain via the 'depends_on' directive, which Docker Compose cannot resolve.
generic中文
在 docker-compose.yml 文件中,服务通过 'depends_on' 指令形成了循环依赖链,Docker Compose 无法解析。
Official Documentation
https://docs.docker.com/compose/compose-file/05-services/#depends_onWorkarounds
-
95% success Redesign the service architecture to remove the circular dependency. For example, if service A needs service B and vice versa, consider merging them into a single service or using a message queue. Update docker-compose.yml to remove the cycle.
Redesign the service architecture to remove the circular dependency. For example, if service A needs service B and vice versa, consider merging them into a single service or using a message queue. Update docker-compose.yml to remove the cycle.
-
85% success Use 'depends_on' with 'condition: service_healthy' and implement health checks instead of direct dependencies. This allows services to start in any order but wait for readiness. Example: 'depends_on: { db: { condition: service_healthy } }'.
Use 'depends_on' with 'condition: service_healthy' and implement health checks instead of direct dependencies. This allows services to start in any order but wait for readiness. Example: 'depends_on: { db: { condition: service_healthy } }'.
中文步骤
Redesign the service architecture to remove the circular dependency. For example, if service A needs service B and vice versa, consider merging them into a single service or using a message queue. Update docker-compose.yml to remove the cycle.
Use 'depends_on' with 'condition: service_healthy' and implement health checks instead of direct dependencies. This allows services to start in any order but wait for readiness. Example: 'depends_on: { db: { condition: service_healthy } }'.
Dead Ends
Common approaches that don't work:
-
70% fail
Removing all depends_on directives breaks the intended startup order and may cause runtime failures if services depend on each other for readiness.
-
80% fail
Adding a third service that depends on both only masks the cycle temporarily; the underlying dependency graph remains invalid.