Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mjagus opened this issue May 1, 2022 · 3 comments

Comments

@mjagus
Copy link

mjagus commented May 1, 2022

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

@mateomartin1998
Copy link

Second this, I have the similar issue with dot in project name in V2.4.1. up works, however not the ps, down. V1 was fine.

@gummif
Copy link

gummif commented May 22, 2022

I am having them same problem. Project names with period in them used to work in v1.29 but I now get "No container found for project" in v2.5 when executing the down command.

@glours
Copy link
Contributor

glours commented Jul 27, 2022

Since the release of Compose v2.5.1 and the version v1.2.5 of compose-go, a project name can't start with _ or contains .
This decision was made to fix potential security issue and if you want to keep your container names as a valid hostname you should avoid using underscore in project or service names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants