Skip to content

[BUG] Docker compose yaml containers using different profiles but same container_name fails #11619

@rhogreen

Description

@rhogreen

Description

We are unable to run docker compose files that contain images using the same container name, but run under different profiles. This works fine in v2.24.6, but is now broken under v2.24.7.

I'd like to be able to use profiles to specify which image I'd like to run and still use the same container name.

Steps To Reproduce

Docker compose file:

version: '3.5'
services:
  python:
    image: python:latest
    container_name: python_image
    profiles:
      - test

  python310:
    image: python:3.10
    container_name: python_image
    profiles:
      - test2

cmd: docker compose --profile test up
error: "services.python310": container name "python_image" is already in use by "services.python": invalid compose project

Install Docker Compose v2.24.6 and this works fine again.

I'd like this feature of docker compose to work again.

Compose Version

Docker Compose version v2.24.7

Docker Environment

Client: Docker Engine - Community
 Version:    25.0.4
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.13.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.7
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 21
  Running: 20
  Paused: 0
  Stopped: 1
 Images: 111
 Server Version: 25.0.4
 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: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.5.0-21-generic
 Operating System: Ubuntu 22.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 24
 Total Memory: 62.53GiB
 Name: moshen
 ID: KMFM:LDXZ:IHYR:KE24:JVVL:4FEM:FF3O:3WCD:LNZF:Q4KG:6SZH:SDK2
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: rho@outsideanalytics.com
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions