You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Compose v2 is recreating ALL containers where there is a change to one of the "depends_on" in the hierarchy (bring back compose v1 behaviour) #10308
Basically, this comment (#9600 (comment)) encompasses this issue. Sometimes containers are completely recreated when we do not expect them to, and when using "depends_on", and a dependant container changes in some way, all of the children are restarted. In compose v1.X, this is NOT the case, and ONLY the changed container is recreated and all others are untouched.
Either this is a bug, or a feature request to bring back compose v1 behaviour (at least with a flag).
Hi @ndeloof ,
I finally got some time to test this today and it didn't work.
These are the steps I followed:
# compose ver:
Docker Compose version v2.17.0-rc.1
docker compose down
docker system prune --all
# clean slate for testing
# update docker-compose.yml as per example below
docker compose up -d
# pulls all 4 images and creates all 4 containers as expected
# Run "docker compose up -d" multiple times, no containers recreated needlessly - good!
docker compose up -d
docker compose up -d
docker compose up -d
# Then, I changed the image tag of service-4 in docker-compose.yml
docker compose up -d
# ALL the dependent containers got recreated :(
[+] Running 4/4
✔ Container dro-dns-fe-pdns-publisher-1 Running 0.0s
✔ Container dro-dns-fe-syslog-ng-1 Started 21.8s
✔ Container dro-dns-fe-pdns-recursor-1 Started 21.2s
✔ Container dro-dns-fe-dnsdist-1 Started 10.8s
# Run "docker compose up -d" multiple times, no containers recreated needlessly - good!
docker compose up -d
docker compose up -d
docker compose up -d
docker compose up -d
# Again, modified the image tag of service-4, ALL the dependent containers got recreated :(
# Run "docker compose up -d" multiple times, no containers recreated needlessly - good!
docker compose up -d
docker compose up -d
docker compose up -d
docker compose up -d
Having same issue as decribed in #10308 (comment) with Compose v2.24.6 (latest from Ubuntu 24.04 feed)
Is this a new by design bahaviour or how to avoid this?
@ndeloof Please can you provide the example of correct usage this option?
I have the same situation as @captainfalcon23 - restart:false is set but conainers still being restarted
I have now spent some time looking into this issue, and as far as I can tell, the restart option of depends_on only applies to the docker compose restart command. At least, that's the only place that the implementation of #10284 touched. However, that does not come into effect when docker compose applies a new convergence on the entire dependency tree.
There's a pair of flags for docker compose up that are supposed to affect whether dependencies are recreated: --always-recreate-deps and --no-recreate; without the presence of either of these two, the recreation strategy should default to RecreateDiverged defined here, as selected by createOptions.dependenciesRecreateStrategy.
Unfortunately, the observed behavior seems to be as if --always-recreate-deps was on by default, but I'm not familiar enough with the internals of the convergence implementation to figure out why RecreateDiverged does not appear to apply.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
There's no indication that this has been addressed in any way. (I hope we don't have to play the stale / bump game every few months for years from here on out.)
@ndeloof That is not what this issue is about, though. Yes, the restart: false option applies correctly when you restart a dependency. However, it has no effect if the dependency is recreated (for example, if you change the runtime configuration, or upgrade the image). As far as I can tell, there is currently no way to configure docker compose to avoid recreating all dependent services in this situation.
Here's an example that involves upgrading the tag in between docker compose up -d runs:
koniiiik@parahippus /tmp/docker-compose-example $ cat docker-compose.yml
services:
service-1:
image: nginx
depends_on:
service-2:
condition: service_started
restart: false
service-2:
image: nginx:1.27.3
koniiiik@parahippus /tmp/docker-compose-example $ docker compose up -d
[+] Running 3/3
✔ Network docker-compose-example_default Created 0.1s
✔ Container docker-compose-example-service-2-1 Started 0.3s
✔ Container docker-compose-example-service-1-1 Started 0.4s
koniiiik@parahippus /tmp/docker-compose-example $ cat docker-compose.yml
services:
service-1:
image: nginx
depends_on:
service-2:
condition: service_started
restart: false
service-2:
image: nginx:1.27.4
koniiiik@parahippus /tmp/docker-compose-example $ docker compose up -d
[+] Running 1/1
✔ service-2 Pulled 2.7s
[+] Running 2/2
✔ Container docker-compose-example-service-2-1 Started 0.5s
✔ Container docker-compose-example-service-1-1 Started 0.5s
koniiiik@parahippus /tmp/docker-compose-example $ docker compose ps -a
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
docker-compose-example-service-1-1 nginx "/docker-entrypoint.…" service-1 17 seconds ago Up 16 seconds 80/tcp
docker-compose-example-service-2-1 nginx:1.27.4 "/docker-entrypoint.…" service-2 17 seconds ago Up 16 seconds 80/tcp
I hope you can see that the issue has not been addressed, and that you reopen it.
Activity
ndeloof commentedon Feb 28, 2023
With #10284 you can now explicitly opt-in/out for dependent container to be restarted when a service is recreated.
captainfalcon23 commentedon Feb 28, 2023
Can you please share how to configure this in compose file? Or link to the docs :) I couldn't see a reference in the MR.
ndeloof commentedon Feb 28, 2023
see https://github.com/compose-spec/compose-spec/blob/master/spec.md#long-syntax-1
captainfalcon23 commentedon Mar 9, 2023
Hi @ndeloof ,
I finally got some time to test this today and it didn't work.
These are the steps I followed:
Sample docker-compose.yml file:
Have I made a mistake in the config, or is it just not working as expected?
andryushchenko commentedon Jul 3, 2024
Having same issue as decribed in #10308 (comment) with Compose v2.24.6 (latest from Ubuntu 24.04 feed)
Is this a new by design bahaviour or how to avoid this?
ndeloof commentedon Jul 3, 2024
@andryushchenko see #10308 (comment)
andryushchenko commentedon Jul 4, 2024
@ndeloof Please can you provide the example of correct usage this option?
I have the same situation as @captainfalcon23 - restart:false is set but conainers still being restarted
koniiiik commentedon Jul 18, 2024
I have now spent some time looking into this issue, and as far as I can tell, the
restartoption ofdepends_ononly applies to thedocker compose restartcommand. At least, that's the only place that the implementation of #10284 touched. However, that does not come into effect when docker compose applies a new convergence on the entire dependency tree.There's a pair of flags for
docker compose upthat are supposed to affect whether dependencies are recreated:--always-recreate-depsand--no-recreate; without the presence of either of these two, the recreation strategy should default toRecreateDivergeddefined here, as selected bycreateOptions.dependenciesRecreateStrategy.Unfortunately, the observed behavior seems to be as if
--always-recreate-depswas on by default, but I'm not familiar enough with the internals of the convergence implementation to figure out whyRecreateDivergeddoes not appear to apply.github-actions commentedon Mar 16, 2025
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
koniiiik commentedon Mar 17, 2025
There's no indication that this has been addressed in any way. (I hope we don't have to play the stale / bump game every few months for years from here on out.)
stale commentedon Mar 17, 2025
This issue has been automatically marked as not stale anymore due to the recent activity.
ndeloof commentedon Mar 17, 2025
@koniiiik using this example compose file:
As you can see, with
restart: falseset, service-1 which depends on restarted service is not impacted.I'm closing this issue as "fixed".
koniiiik commentedon Mar 17, 2025
@ndeloof That is not what this issue is about, though. Yes, the
restart: falseoption applies correctly when you restart a dependency. However, it has no effect if the dependency is recreated (for example, if you change the runtime configuration, or upgrade the image). As far as I can tell, there is currently no way to configure docker compose to avoid recreating all dependent services in this situation.Here's an example that involves upgrading the tag in between
docker compose up -druns:I hope you can see that the issue has not been addressed, and that you reopen it.
ndeloof commentedon Mar 17, 2025
indeed, thanks for clarification (it's hard to get a clear understanding on the many issues we have to address within my limited brain :P)
koniiiik commentedon Mar 17, 2025
No worries, we've all been there. And at least now we have a truly minimal example to reproduce the issue.