Quick question! Docker homepage states that
There are several things to be aware of when using depends_on:
depends_on does not wait for db and redis to be “ready” before starting web - only until they have been started. If you need to wait for a service to be ready, see Controlling startup order for more on this problem and strategies for solving it.
The depends_on option is ignored when deploying a stack in swarm mode with a version 3 Compose file.
so does this mean when I'm using swarm mode and version 3 compose file to deploy it will ignore all conditions under depends_on? for example
version: "3"
services:
web:
build: .
ports:
- "80:8000"
depends_on:
- "db"
command: ["./wait-for-it.sh", "db:5432", "--", "python", "app.py"]
db:
image: postgres
CodePudding user response:
Pretty correct, swarm
as a orchestration will ignore the depends_on
.
But for your scenario, depends_on
is really not necessary as you already have wait-for-it.sh
which have better control than depends_on
to assure the start order.
You can control the order of service startup and shutdown with the depends_on option. Compose always starts and stops containers in dependency order, where dependencies are determined by depends_on, links, volumes_from, and network_mode: "service:...".
However, for startup Compose does not wait until a container is “ready” (whatever that means for your particular application) - only until it’s running. There’s a good reason for this.
There are limitations to this first solution. For example, it doesn’t verify when a specific service is really ready.
Alternatively, write your own wrapper script to perform a more application-specific health check. For example, you might want to wait until Postgres is ready to accept commands
Details see Control startup and shutdown order in Compose, so you no need depends_on
in your solution.