Skip to content

the --exit-code-from is 0 from a service that depends_on when another container exited #9778

Closed
@Lenormju

Description

@Lenormju

Description

I want to use Compose to test my services. I use --exit-code-from test to get the exit code of my test service, which is very convenient.
As mentioned in the docs, --exit-code-from implies --abort-on-container-exit, which is very useful in my case : if any service crashes, the test can be considered a failure.
But if my test service has a depends_on on any other service, then I don't get the exit code anymore, just 0.

Steps to reproduce the issue:

  1. file: docker-compose.yml
    ---
    name: mre__exit_code_from__when_other_container_aborts
    services:
      safe:
        image: 'ubuntu:20.04'
        command: ['/usr/bin/bash', '-c', 'sleep 30']
      failure:
        image: 'ubuntu:20.04'
        command: ['/usr/bin/bash', '-c', 'sleep 2 ; echo "exiting" ; exit 42']
      test:
        image: 'ubuntu:20.04'
        command: ['/usr/bin/bash', '-c', 'sleep 30']
        depends_on: [safe]
    ...
  2. run (linux) docker compose down ; docker compose up --abort-on-container-exit --exit-code-from test ; echo "EXIT_CODE=$?" ; docker ps -a --filter 'name=mre__exit_code_from__when_other_container_aborts'

Describe the results you received:

[+] Running 4/3
 ⠿ Network mre__exit_code_from__when_other_container_aborts_default      Created                                                                                                                                                    0.1s
 ⠿ Container mre__exit_code_from__when_other_container_aborts-failure-1  Created                                                                                                                                                    0.1s
 ⠿ Container mre__exit_code_from__when_other_container_aborts-safe-1     Created                                                                                                                                                    0.1s
 ⠿ Container mre__exit_code_from__when_other_container_aborts-test-1     Created                                                                                                                                                    0.1s
Attaching to mre__exit_code_from__when_other_container_aborts-failure-1, mre__exit_code_from__when_other_container_aborts-safe-1, mre__exit_code_from__when_other_container_aborts-test-1
mre__exit_code_from__when_other_container_aborts-failure-1  | exiting
mre__exit_code_from__when_other_container_aborts-failure-1 exited with code 42
Aborting on container exit...
[+] Running 3/3
 ⠿ Container mre__exit_code_from__when_other_container_aborts-test-1     Stopped                                                                                                                                                   10.4s
 ⠿ Container mre__exit_code_from__when_other_container_aborts-failure-1  Stopped                                                                                                                                                    0.0s
 ⠿ Container mre__exit_code_from__when_other_container_aborts-safe-1     Stopped                                                                                                                                                   10.4s
ERRO[0024] 137                                          
ERRO[0024] 0                                            
EXIT_CODE=0
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                                PORTS     NAMES
c00c28b861ea   ubuntu:20.04   "/usr/bin/bash -c 's…"   24 seconds ago   Exited (137) 10 seconds ago                     mre__exit_code_from__when_other_container_aborts-test-1
d7a924757da7   ubuntu:20.04   "/usr/bin/bash -c 's…"   24 seconds ago   Exited (137) Less than a second ago             mre__exit_code_from__when_other_container_aborts-safe-1
56713d9643b8   ubuntu:20.04   "/usr/bin/bash -c 's…"   24 seconds ago   Exited (42) 21 seconds ago                      mre__exit_code_from__when_other_container_aborts-failure-1

The exit code of the program is 0.

Describe the results you expected:
The exit code of the program is 137.

Additional information you deem important (e.g. issue happens only occasionally):
Reproducible repeatedly with the command I supplied.
Commenting out the depends_on line gets the expected result.
Among the 6 depends_on permutations, only this one exhibits this behavior, the other 5 return 137.
If test finishes early (for example with command: ['/usr/bin/bash', '-c', 'exit 18']) then it does not have to be forced to stop, and the exit code is the expected one.

Output of docker compose version:

docker version
Client: Docker Engine - Community
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:48:02 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       87a90dc
  Built:            Thu Mar 24 01:45:53 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.11
  GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker compose version:

Docker Compose version v2.3.3

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.1-docker)
  compose: Docker Compose (Docker Inc., v2.3.3)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 13
  Running: 3
  Paused: 0
  Stopped: 10
 Images: 124
 Server Version: 20.10.14
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 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: 3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc version: v1.0.3-0-gf46b6ba
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.11.0-38-generic
 Operating System: Ubuntu 20.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 31.26GiB
 Name: [REDACTED]
 ID: XJXT:QSMF:UNWH:4VTI:HD5T:MBMN:EZJL:GYQ6:VOPO:2U6Q:3TVF:BQPH
 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:
Reproduced on Windows (Docker Desktop).

Metadata

Metadata

Assignees

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