Skip to content

[BUG] --index for docker-compose exec command does not choose right container #12219

@gburzynski-10clouds

Description

@gburzynski-10clouds

Description

I have 2 containers created from the same service server. One with backend, second with tests. I want to exec into backend container.

e99c12cd8eeb   d1cc9cdbcd1b   "./run_tests.sh"   28 minutes ago   Up 28 minutes                                                     server-run-68082c734962
e24541534a85   d1cc9cdbcd1b   "python manage.py ru…"   29 minutes ago   Up 29 minutes   0.0.0.0:8001->8001/tcp, :::8001->8001/tcp         server

Doesn't matter if I run:
docker-compose --file docker-compose.yml exec -t --index 0 server bash
or docker-compose --file docker-compose.yml exec -t --index 1 server bash
I end up inside test container (can be checked by looking into running processes ps aux.)

Workaround: docker-compose exec execs always into container that was created last.

Steps To Reproduce

  1. Define server service in docker-compose.yml
  2. Run one instance docker-compose --file docker-compose.yml run --rm --name server server python
  3. Run second instance docker-compose --file docker-compose.yml run --rm server ./run_tests.sh
  4. See the docker ps -a output to get the index of container
  5. Notice that passed index does not change to which container we exec into docker-compose --file docker-compose.yml exec -t --index 1 server bash

Compose Version

2.29.7

Docker Environment

docker info
Client: Docker Engine - Community
Version: 27.3.1
Context: colima-redacted
Debug Mode: false

Server:
Containers: 4
Running: 4
Paused: 0
Stopped: 0
Images: 4
Server Version: 27.1.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: cgroupfs
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: 472731909fa34bd7bc9c087e4c27943f9835f111
runc version: v1.1.13-0-g58aa920
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.8.0-41-generic
Operating System: Ubuntu 24.04.1 LTS
OSType: linux
Architecture: aarch64
CPUs: 8
Total Memory: 9.69GiB
Name: colima-redacted
ID: af1bee08-e490-44cd-a00a-c182c012f6f4
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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions