Skip to content

Compose v2: Inconsistent behaviour between commands when project name has leading underscores #9429

@mjagus

Description

@mjagus

Description

Passing a project name containing any amount of leading underscores to up command causes those underscores to be silently removed when container names are generated. This is inconsistent with down command, which does not seem to be taking that into account anymore (it did in Docker Compose v1). This breaks some automated tools that depend on Docker Compose, because they are able to create containers by providing such project name, but are unable to stop or remove them due to name mismatch.

Steps to reproduce the issue:

  1. Create docker-compose.yml file with following content
version: '3'

services:
        service:
                image: nginxdemos/hello
  1. Download docker compose v1.29.2: wget https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64 && mv docker-compose-Linux-x86_64 docker-compose_1.29.2

  2. Download docker compose v2.5.0: wget https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-x86_64 && mv docker-compose-linux-x86_64 docker-compose_2.5.0

  3. add exec permissions: chmod +x docker-compose_*

  4. Run following commands on both versions

./docker-compose_1.29.2 -p _my-project up -d
./docker-compose_1.29.2 -p _my-project down

./docker-compose_2.5.0 -p _my-project up -d
./docker-compose_2.5.0 -p _my-project down

Describe the results you received:

v1.29.2 correctly removed the container during execution of down command, whereas v2.5.0 failed with an error.

Output of v1.29.2:

  • up:
Creating network "_my-project_default" with the default driver
Creating my-project_service_1 ... done
  • down:
Stopping my-project_service_1 ... done
Removing my-project_service_1 ... done
Removing network _my-project_default

Output of v2.5.0:

  • up:
[+] Running 2/2
 ⠿ Network my-project_default      Created
 ⠿ Container my-project-service-1  Started 
  • down:
no container found for project "_my-project": not found

Describe the results you expected:

I expected v2.5.0 to correctly remove the container during execution of down command.

Additional information you deem important (e.g. issue happens only occasionally):

The same behaviour is present in 2.4.1 so it's not a recent regression. The same issue also applies to start, stop and probably other commands too.

Output of docker compose version:

./docker-compose_1.29.2 --version
docker-compose version 1.29.2, build 5becea4c

./docker-compose_2.5.0 --version
Docker Compose version v2.5.0

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.1-docker)
  compose: Docker Compose (Docker Inc., 2.4.1)

Server:
 Containers: 12
  Running: 2
  Paused: 0
  Stopped: 10
 Images: 91
 Server Version: 20.10.14
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: false
  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 logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: de8046a5501db9e0e478e1c10cbcfb21af4c6b2d.m
 runc version: 
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.109-1-MANJARO
 Operating System: Manjaro Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 31.33GiB
 Name: jagger
 ID: V5VN:ANL5:O35G:O2ZM:YSQ6:777Q:SIHN:W6LU:KYLV:EKJG:6RUU:XF72
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details:

none

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions