Docker return codes from background commands

I’m not getting the return code I expect, when executing a script inside a Docker container with a background task run in it.

This example docker file highlights the problem:

  • How much maximum heap space does a Play Framework App use per default
  • python: PyPi public modules: How to determine if secure and safe?
  • How to pass Chef data bag secret to a docker container?
  • Error Accesing to container on Bluemix
  • Docker Compose run that takes user input crashes with “broken pipe”
  • docker-compose: difference between network and link
  • FROM ubuntu:latest
    MAINTAINER Jakob H. Thomsen (jakob@gedefar.dk)
    
    RUN echo "#!/bin/bash\nset -e\n\nls / &\nexit 1" > /start_script.sh
    RUN chmod +x /start_script.sh 
    

    It creates the following file /start_script.sh inside the container:

    #!/bin/bash
    set -e
    
    ls / &
    exit 1
    

    So running docker build -t jakob/test . and docker run jakob/test cat /start_script.sh you would expect the return code to be 1, because of the exit 1. It is not, it is 0 and it is somehow because of the ls / & (if you remove that command you get the expected return code of 1).

    So my question is why ls / & overrides the return code of the exit 1 command? I tried making exit 1 to run in the background, but it doesn’t change the return code…

    As I’m using the setup to run Ruby specs, I’m really dependent upon the return code of the last command, so is there something I can do to make Docker return the return code of the last command?

    Thanks and I hope you can help, as it has taking me a loong time to pinpoint the exact issue of these ‘wrong’ return codes.

  • How can I run docker-compose up as shell script by Jenkins
  • Move docker-machine to another computer
  • Docker error while creating couchbase - ulimit: open files: cannot modify limit: Operation not permitted
  • How containerd compares to runC
  • How to use Docker Swarm On Mesos?
  • Re-running Docker only until a certain step using caches?
  • One Solution collect form web for “Docker return codes from background commands”

    Turned out that the issue is fixed in the newest version of Docker: https://github.com/dotcloud/docker/issues/3775

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.