3

docker-compose return code upon run completion is always ZERO

[nlakshmi@ROSE02T44GUH03Q database]$ docker-compose up
Recreating database_database_1 ... done
Attaching to database_database_1
database_1  | + mkdir -p -m 0755 /opt/adp/logs/db_tester/rpm/installs/
database_1  | + '[' -z abcd ']'
database_1  | + /root/bin/generateDBConfigData_FromManifest.sh abcd
database_1  | /tmp/manifest_02042019_143116.txt: line 1: syntax error near unexpected token `<'
database_1  | /tmp/manifest_02042019_143116.txt: line 1: `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Oops, can&#39;t find that - Bitbucket</title><script>'
database_1  | Starting work......
database_1  | Starting clones.....
database_1  | Let us clone the config templates for tag
database_1  | fatal: Invalid refspec '+refs/tags/:refs/tags/'
database_1  | ERROR - prrs_repository wans't informed
database_1  | + source /tmp/abcd
database_1  | /root/bin/install_db.sh: line 43: /tmp/abcd: No such file or directory
database_1  | + '[' x == x ']'
database_1  | + echo 'ERROR - prrs_repository wans'\''t informed'
database_1  | + exit 1
database_database_1 exited with code 1


[nlakshmi@ROSE02T44GUH03Q database]$ echo $?
0

I ran docker-compose up and the output pasted above shows that even though the container failed, docker-compose did not exit with the right error code. In this case I was expecting NON-ZERO exit code from docker-compose up

What gives ?

Bless
  • 5,052
  • 2
  • 40
  • 44
savithari
  • 107
  • 1
  • 9

1 Answers1

2

To return the exit code of the container back to the docker-compose up command, pass --exit-code-from SERVICE argument to docker-compose up command.

docker-compose up --exit-code-from database

Assuming you want the exit code from the database service to be returned.

Note: This also implies that all containers will be stopped if any container was stopped.

Reference - https://docs.docker.com/compose/reference/up/

Bless
  • 5,052
  • 2
  • 40
  • 44