Web service tries to start before app is ready #152

Open
opened 2026-10-22 08:08:25 +00:00 by amras · 7 comments
Owner

Current behavior: The app service takes several minutes to start and reach a healthy state. In the meantime, web attempts deployment over 10 times, reporting "unhealthy" each time.

Proposed solution: The depends-on attribute is already set on web. We should probably switch from the short syntax

depends-on:
 - app

to the long syntax

depends-on:
 app:
  - condition: service_healthy

More info on the compose file reference

**Current behavior**: The `app` service takes several minutes to start and reach a healthy state. In the meantime, `web` attempts deployment over 10 times, reporting "unhealthy" each time. **Proposed solution**: The `depends-on` attribute is already set on `web`. We should probably switch from the short syntax ```yaml depends-on: - app ``` to the long syntax ```yaml depends-on: app: - condition: service_healthy ``` [More info on the compose file reference](https://docs.docker.com/reference/compose-file/services/#depends_on)
amras changed title from Fix "depends-on" order to Web service starts before app is ready 2026-10-22 08:08:56 +00:00
amras changed title from Web service starts before app is ready to Web service tries to start before app is ready 2026-10-22 08:09:08 +00:00
Author
Owner

Might be good to do a full pass of dependencies and ensure other services don't start too early either.

Might be good to do a full pass of dependencies and ensure other services don't start too early either.
amras added the bug label 2026-10-22 08:13:17 +00:00
Owner

Did you try this out? I always thought (and also experienced, IIRC), that docker swarm ignores depends-on. Here is an old documentation which states so: https://github.com/docker/compose/blob/v1/docs/Compose%20file%20reference%20(legacy)/version-3.md#depends_on

Claude proposes this instead:

Fixes that do work in Swarm:

  • Make nginx look up the address when a request arrives, not at startup. Use Docker's internal DNS server and a variable, so nginx starts even if app isn't up yet:
    resolver 127.0.0.11 valid=10s;
    set $php_upstream {{ env "STACK_NAME" }}_app:9000;
    fastcgi_pass $php_upstream;
    This replaces the upstream php-handler block. Until app is up, requests get a 502 instead of nginx crashing.
  • Give web's healthcheck the same time as app's: set start_period: 15m for web too. Or make it only check nginx itself, e.g. a static location /nginx-health { return 200; }, so it
    stops depending on app.
  • Optionally, add a wait loop to web's entrypoint that waits until app:9000 is reachable before starting nginx. That's the usual Swarm stand-in for depends_on.
Did you try this out? I always thought (and also experienced, IIRC), that docker swarm ignores `depends-on`. Here is an old documentation which states so: https://github.com/docker/compose/blob/v1/docs/Compose%20file%20reference%20(legacy)/version-3.md#depends_on Claude proposes this instead: Fixes that do work in Swarm: - Make nginx look up the address when a request arrives, not at startup. Use Docker's internal DNS server and a variable, so nginx starts even if app isn't up yet: resolver 127.0.0.11 valid=10s; set $php_upstream {{ env "STACK_NAME" }}_app:9000; fastcgi_pass $php_upstream; This replaces the upstream php-handler block. Until app is up, requests get a 502 instead of nginx crashing. - Give web's healthcheck the same time as app's: set start_period: 15m for web too. Or make it only check nginx itself, e.g. a static location /nginx-health { return 200; }, so it stops depending on app. - Optionally, add a wait loop to web's entrypoint that waits until app:9000 is reachable before starting nginx. That's the usual Swarm stand-in for depends_on.
ineiti added the question label 2026-10-22 08:18:34 +00:00
Author
Owner

Oh, interesting. The new docs don't mention the swarm limitation - I wonder if it's been removed. If I find the time I'll run some experiments, unless someone else beats me to it.

None of the workarounds you propose spark joy. If the swarm limitation is still applicable, my vote would be to leave it as-is, and just let web spin its tires for a few minutes.

Oh, interesting. The new docs don't mention the swarm limitation - I wonder if it's been removed. If I find the time I'll run some experiments, unless someone else beats me to it. None of the workarounds you propose spark joy. If the swarm limitation is still applicable, my vote would be to leave it as-is, and just let `web` spin its tires for a few minutes.
Owner

According to https://github.com/docker/docs/issues/21079 they removed it, as docker swarm is no longer officially part of docker...

So we should perhaps remove all depends_on to make sure nobody thinks this is actually doing something useful :)

Now that I think about it: usually when I deploy nextccloud, the app is started after all other services - I wonder if that's a coincidence, or what's happening there?

According to https://github.com/docker/docs/issues/21079 they removed it, as docker swarm is no longer officially part of docker... So we should perhaps remove all `depends_on` to make sure nobody thinks this is actually doing something useful :) Now that I think about it: usually when I `deploy` nextccloud, the `app` is started after all other services - I wonder if that's a coincidence, or what's happening there?
Author
Owner

Looking through some more docs, looks like "all the services keep restarting until the stack works" is the design intent in swarm.

Agree that we should remove depends_on from the recipe. Maybe even make a note in the maintainer's handbook.

Looking through some more docs, looks like "all the services keep restarting until the stack works" is the design intent in swarm. Agree that we should remove `depends_on` from the recipe. Maybe even make a note in the maintainer's handbook.
Author
Owner

Now that I think about it: usually when I deploy nextccloud, the app is started after all other services - I wonder if that's a coincidence, or what's happening there?

I assume that's a combination of the app having an internal wait for the db connection, and nextcloud just being a bit bloated.

> Now that I think about it: usually when I deploy nextccloud, the app is started after all other services - I wonder if that's a coincidence, or what's happening there? I assume that's a combination of the app having an internal wait for the db connection, and nextcloud just being a bit bloated.
Owner

I assume that's a combination of the app having an internal wait for the db connection, and nextcloud just being a bit bloated.

and mental bias - I just redeployed, and it was another service starting as the latest...

> I assume that's a combination of the app having an internal wait for the db connection, and nextcloud just being a bit bloated. and mental bias - I just redeployed, and it was another service starting as the latest...
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: coop-cloud/nextcloud#152