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

  1. 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)

Most upvoted comments

The intent of this feature is to be equivalent to coding language include|import|require dependency management: your “code” uses third party components, and those are (in most case) close to extension.

This is only partially true. An include|import|require statement in code will also recursively resolve all the includes|imports|requires of the dependency, BEFORE moving to the next dependency.

If I specify a sequence of compose files, let’s say a.yaml, b.yaml, and c.yaml, I expect (using the “code” analogy) each to be fully resolved in order: first a and its dependencies, second b and its dependencies, and finally c and its dependencies.

Also, the docs state:

include makes it easier to modularize complex applications into sub-Compose files. This allows application configurations to be made simpler and more explicit. This also helps to reflect in the config file organization the engineering team responsible for the code.

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 include it still doesn’t work with service.XXXX conflicts with imported resource message.

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:

include:
  - services/test.yaml

services/test.yaml:

services:
  test:
    image: hello-world
    environment:
      BREAKING: "false"

Before the update, devs could define local overrides such as ports and envars in compose.override.yaml.

services:
  test:
    environment:
      BREAKING: "true"

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.

include makes it easier to modularize complex applications into sub-Compose files. This allows application configurations to be made simpler and more explicit. This also helps to reflect in the config file organization the engineering team responsible for the code.

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. include is 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:

include:
  - path: 
      - postgresql.yml
      - postgresql.override.yml

you can then use this postgresql.override.yaml file to tweak the service being imported in your application

The pipeline to parse, include and override compose yaml files has been redesigned with latest release. include is 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:

include:
  - path: 
      - postgresql.yml
      - postgresql.override.yml

you can then use this postgresql.override.yaml file to tweak the service being imported in your application

This does not seem to work for me. My overrides won’t work, even when I add the - path as shown and include as shown. I’ve tried several permutations, and continue to get conflicts with imported resource errors. 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 have services: in these overrides.

Not sure how the Docker team anticipated people to use docker-compose.override.yml in 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 include instead of extends, 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.

Anyway I could ask : why isn’t the included compose file usable without an override ?

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 include comes from. We need to investigate how we can provide an explicit (i.e. documented and long-terms supported) way to tweak an imported model

I 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:

  1. We have many microservices, each microservice has its own compose file with the main configuration (port, env, etc)
  2. We have a separate mono repository that connects all microservices as git submodules. 2.1. Here we extend the compose file of each service and add general custom things like volumes and depends_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.yml includes groups of services (2.2.) that we need by default + env_file 2.4. docker-compose.override.yml - here we override the service using extends

Also, we use ${PWD} and I see that the path is being generated incorrectly. I see this if I try to run docker compose build from the root folder of the mono repository (found that it is because of build context with . value)

Everything worked before the update.