compose: [BUG] Got services.NAME conflicts with imported resource after update from 2.21.0 to 2.24.1
Description
I have configuration based on this example https://docs.docker.com/compose/multiple-compose-files/include/#example. There three files:
# postgresql.yml
version: '3'
services:
postgres:
image: postgres
# compose.yml
version: '3'
include:
- postgresql.yml
# compose.override.yml
version: '3'
services:
postgres:
ports:
- 5432:5432
With docker compose v2.24.1, it shows error:
$ docker compose version
Docker Compose version v2.24.1
$ docker compose config
services.postgres conflicts with imported resource
But it works well with v2.21.0:
$ docker compose version
Docker Compose version v2.21.0
$ docker compose config
name: compose
services:
postgres:
image: postgres
networks:
default: null
ports:
- mode: ingress
target: 5432
published: "5432"
protocol: tcp
networks:
default:
name: compose_default
Steps To Reproduce
- Create directory with files above and run docker compose up (or config)
Compose Version
$ docker compose version
Docker Compose version v2.24.1
Docker Environment
$ docker info
Client: Docker Engine - Community
Version: 25.0.1
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.12.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.24.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
scan: Docker Scan (Docker Inc.)
Version: v0.23.0
Path: /usr/libexec/docker/cli-plugins/docker-scan
Server:
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 682
Server Version: 25.0.1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: a1496014c916f9e62104b33d1bb5bd03b0858e59
runc version: v1.1.11-0-g4bccb38
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.1.0-17-amd64
Operating System: Debian GNU/Linux 12 (bookworm)
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 15.48GiB
Name: ishkulov
ID: V27O:S3O2:3SYQ:VHRF:HYQB:4CBG:APXI:JHXG:HFAX:CR4P:K5TG:AHMX
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Anything else?
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 20
- Comments: 20 (6 by maintainers)
This is only partially true. An
include|import|requirestatement in code will also recursively resolve all theincludes|imports|requiresof the dependency, BEFORE moving to the next dependency.If I specify a sequence of compose files, let’s say
a.yaml,b.yaml, andc.yaml, I expect (using the “code” analogy) each to be fully resolved in order: firstaand its dependencies, secondband its dependencies, and finallycand its dependencies.Also, the docs state:
This is a common usage. The new behavior denies the possibility to tweak the default configuration (e.g. test a new image, add a network, change a port, etc) without modifying the original compose files.
This completely broke my setup as well. I have a bunch of services defined in their own compose files where they can run individually. I also have another compose file that includes all of them and apply some overrides so some of the services can start to talk to each other.
Now even if I include the override file as the last
includeit still doesn’t work withservice.XXXX conflicts with imported resourcemessage.More importantly, why is this change not mentioned anywhere in your changelog? This is a major behaviour change that is clearly not backwards compatible.
The update unfortunately broke our setup as well.
Take the following example:
compose.yaml:services/test.yaml:Before the update, devs could define local overrides such as ports and envars in
compose.override.yaml.After the update this results in the error:
services.test conflicts with imported resource.I don’t see why this is an unusual use-case? And I can’t find any mention in the docs of included services not being override-able.
This statement also seems to support the use-case of breaking services into separate files as a means of organization.
What would be the “idiomatic” Docker Compose approach to achieve this?
The pipeline to parse, include and override compose yaml files has been redesigned with latest release.
includeis applied as last step in this process, the logic with this attribute is that you rely on a compose file designed by third party, as an atomic building block. The included resources are not supposed to be “patched” by your own compose files. Still, you can define imported resources with an override to match your use-case:you can then use this
postgresql.override.yamlfile to tweak the service being imported in your applicationThis does not seem to work for me. My overrides won’t work, even when I add the
- pathas shown and include as shown. I’ve tried several permutations, and continue to getconflicts with imported resourceerrors. As indicated by other posters, I have to split every single override into its own file now, even though the syntax is unchanged - i still need to haveservices:in these overrides.Not sure how the Docker team anticipated people to use
docker-compose.override.ymlin the first place - why offer it and then deprecate it without warning? If it wasn’t meant to override someone else’s docker-compose file… why make it exist in the first place?I don’t remember how exactly I ended up using
includeinstead ofextends, but that’s the set up I have been using for a year or so. Given the comments by other users there are clearly other similar use-cases as I have. This is just a bit frustrating from an end-user perspective. If an upstream change is going break my setup then I would expect this to be communicated clearly, at the very least.We use a compose.yml file for local development, as it describes all the services required for the project. Developers can modify ports in the compose.override.yml file as needed for local development and to prevent conflicts. Additionally, we include services in other files for environment-specific configurations, such as compose.testing.yml or compose.review.yml, as “reusable block” but not all of them.
So, if I have 10 services included, I have to create 10 separate override files to change ports. That’s sad
My use case is to allow a user to specify an environment variable for their local network subnet atop an included Suricata container that is otherwise configured. Like others, it’s unwieldy (gitignore, Makefile, etc) to have multiple include files for different services/networks/etc, so would appreciate having this functionality restored. Thank you!
The analogy I used here was not to dictate a behavior, but to explain where
includecomes from. We need to investigate how we can provide an explicit (i.e. documented and long-terms supported) way to tweak an imported modelI fully understand your frustration with this unexpected change, not sure yet how we can manage this. This is the first time such a usage has been reported since we introduced
include, if we want this to be supported we would need to add such a scenario to the test suite and get this fully documented.We also experiencing this issue after upgrading.
Our flow:
volumesanddepends_on. 2.2. We have compose files, which include separate service’s compose files into one, like a group of services. 2.3.docker-compose.ymlincludes groups of services (2.2.) that we need by default +env_file2.4.docker-compose.override.yml- here we override the service using extendsAlso, we use
${PWD}and I see that the path is being generated incorrectly. I see this if I try to rundocker compose buildfrom the root folder of the mono repository (found that it is because of build context with.value)Everything worked before the update.