compose: [BUG] service can't be used with `extends` as it declare `depends_on`
Description
When trying to bring up a compose project that makes use of extends feature, I am getting the following error:
service "nginx" can't be used with `extends` as it declare `depends_on`
Steps To Reproduce
- Have a docker-compose.yml project with extends, like this:
nginx:
extends:
file: ./nginx/compose.yml
service: nginx
container_name: "${SERVER_NAME:}-nginx"
env_file: .env
and the nginx/compose.yml:
version: "3.9"
services:
nginx:
image: nginx:1
restart: unless-stopped
depends_on:
- web_app
volumes:
- ./html:/var/www/html
-
docker compose up -
See error: service “nginx” can’t be used with
extendsas it declaredepends_on
Compose Version
2.24.6
Docker Environment
N/A
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 33
- Comments: 47 (10 by maintainers)
encountering this too. why is a breaking change being included in a patch release at all?
This is the expected behavior, see https://github.com/compose-spec/compose-spec/blob/master/05-services.md#restrictions
This seems to be a new restriction added in 2.24.6. We have an
extendscombined withdepends_onand everything was working fine with 2.24.5 and previous versions. Not sure why this wasn’t flagged as a breaking change?restriction already was implemented in 2.23.x, new compose parser used in 2.24.x prior to latest release was just missing this check.
will be part of tomorrow’s release
This makes reusing blocks much harder, as fragments cannot be used across files. As far as I know, using
extendswas the only way to have reusabledepends_onblocks while allowing to separate services in multiple files and have a common file to extend from.@ndeloof please take a look how many linked issues this change produced. I vote for reverting this behavior. Мy company also has tens of projects with currently broken
depends_on@dmitryuk already in progress: https://github.com/compose-spec/compose-spec/pull/470
This issue was closed two weeks ago as
not planned.Shouldn’t it be reopened, now that the relevant restriction in
compose-spechas been lifted?Extending depends_on was working before this change.
Yeah, same for me. Was working fine on
2.24.5and broke on this new2.24.6release.@matthiasPOE no, we relaxed this restriction in the spec https://github.com/compose-spec/compose-spec/pull/470 issue is closed by release v2.26.0
That is not sufficient. It is common to do stuff like have an image like “background worker” and then have 3 instances of it - high-pri, medium-pri, and low-pri. You could then have the base depend on stuff like your DB and message bus and such, then just have 3 instances that extend the base. Now you have to repeat those dependencies over and over in the instantiations. This is definitely more degradation in compose.
We have used Compose for development purposes with a Kubernetes cluster for deployment. It deeply feels like Compose has been losing functionality while Kubernetes has been gaining it, and Kind is becoming more and more compelling to replace Compose from these sorts of things.
Hello there, do we have an ETA for the version 2.25 to be released on Docker Desktop? My company heavily depends on this fix, for now I workaround the issue by download docker-compose instead and working with it, but the entire company is trained on the platform to use docker compose - would be nice to have the fix in place.
@davidlougheed compose-go/v2 is not “not-even-prod-ready”. We released as RC as we anticipated the need for some additional refactoring, and don’t want third party library to suffer from API changes.
THAT BEING SAID: as compose-go includes a consistency check, it would be able to detect reference to another service is orphaned after being used by
extends, such a check docker compose v1 didn’t implemented (so this rule in the compose file format, inherited by the compose specification). With the updated architecture of compose-go/v2 we can now relax this constraint, and offer more flexibility to users (which still should read the docs before they complain about a feature :trollface:). I’ll write a proposal in the compose-spec repo for this purpose, so we can get this both fixed in the docs and in the code@beni0888 you didn’t link the video 🙂
Any idea about when the fix will be released in OSX Docker Desktop?
@r3nor Try now, latest published version fixed it for me (2.25.0).
Thanks @ndeloof !
Got this error with ubuntu update
from docker-compose-plugin (2.24.6-1~ubuntu.22.04~jammy) to (2.24.5-1~ubuntu.22.04~jammy)
You’re right! Fixed!!
In case someone else is facing issues because Docker Desktop is still running an old version of the docker-compose plugin, I’ve found this useful video explaining how to easily upgrade the docker-compose plugin used by Docker Desktop.
should happen in a few days
Thanks @ndeloof for fixing the spec.
The change broke my project as I have the base
docker-compose.yamlwhich declares my API server (whichdepends_ona database image) built from the project source (ie: compiling code) and a.devcontainer/docker-compose-dev.yamlwhichextendsthe base service, but changes thebuild.targetso that an image is used that has all the developer dependencies and mounts the source files.This used to work so that the developer image/container would still depend on the DB which worked well for the development team.
BTW I don’t think you were able to overwrite
depends_onbefore. What you happen is that theirdepends_onwould be merged with yours.I want to reuse another developers service without making them change their code. If I ‘include’ I am stuck with their implementation. why can’t I just overwrite with my own ‘depends_on’ and move on?
The problem with this approach is that if more than one service derives from the base service (and this is always the case — why would you go into the effort of sharing functionality if there is just one service), you will need to copy-paste the “depends_on” stanza into each one. Also, if there is more than one service in the derivation chain, it will make the derived services unusable on their own, i.e. consider a situation where you have service “x" extending service “y" which extends service “z”, all of which depend on the service “foo”. This change moves the “depends_on foo” logic from z to x. Before this change, you could happily start a container with services z and y, while after the change, only service x is usable.
On Feb 28, 2024 at 4:41:39 AM, luciangabor @.***> wrote:
… and if you want to “inherit” the depends_on,
deps.yamlcould be like this: