Bug 1097344

Summary: Docker run exit code consistency
Product: Red Hat Enterprise Linux 7 Reporter: Chris Evich <cevich>
Component: docker-latestAssignee: Lokesh Mandvekar <lsm5>
Status: CLOSED ERRATA QA Contact: atomic-bugs <atomic-bugs>
Severity: high Docs Contact:
Priority: medium    
Version: 7.0CC: cevich, dwalsh, lsm5, lsu, santiago, sdodson, somalley
Target Milestone: rcKeywords: Extras
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1162807 (view as bug list) Environment:
Last Closed: 2016-05-12 14:52:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1303656    

Description Chris Evich 2014-05-13 15:17:50 UTC
Description of problem:
The docker run operation should never return a non-zero exit code.

Version-Release number of selected component (if applicable):
docker-0.10.0-10.el7.x86_64

How reproducible:
very

Steps to Reproduce:
1. # docker run fedora:20 /bin/false; echo $?
2. # docker run this_image_does_not_exist /bin/false; echo $?

Actual results:
# docker run fedora:20 /bin/false; echo $?
1
Unable to find image 'this_image_does_not_exist' locally
Pulling repository this_image_does_not_exist
2014/05/13 11:08:53 HTTP code: 404
1

Expected results:
Unable to find image 'this_image_does_not_exist' locally
Pulling repository this_image_does_not_exist
2014/05/13 11:08:53 HTTP code: 404
0

Additional info:
If docker CLI and contained-process both return exit code 1, how is automated control of 'docker run' to tell the difference (other than by examining error messages).  See also Bug 1097334

Additional Additional info:
Marking this high because it affects CI, just as 1097334.  One or the other should be fixed ASAP.

Comment 1 Daniel Walsh 2014-05-19 18:03:26 UTC
Not sure what to do here.  I would guess that you do not want the exit codes from within the container to return to $?

docker run --rm fedora sh -c 'exit 2'; echo $?
2

But I think this is expected.

Comment 2 Chris Evich 2014-05-19 20:41:14 UTC
(In reply to Daniel Walsh from comment #1)
> Not sure what to do here.  I would guess that you do not want the exit codes
> from within the container to return to $?
> 
> docker run --rm fedora sh -c 'exit 2'; echo $?
> 2
> 
> But I think this is expected.

See https://bugzilla.redhat.com/show_bug.cgi?id=1097334#c3 and https://bugzilla.redhat.com/show_bug.cgi?id=1097334#c4

Comment 3 Daniel Walsh 2014-06-27 16:42:07 UTC
chroot command has a close relationship to this

  Exit status:

     125 if 'chroot' itself fails
     126 if COMMAND is found but cannot be invoked
     127 if COMMAND cannot be found
     the exit status of COMMAND otherwise

Comment 4 Daniel Walsh 2014-06-27 16:42:31 UTC
I have raised this issue with upstream


https://github.com/dotcloud/docker/issues/6734

Comment 5 Chris Evich 2014-06-27 17:57:09 UTC
Great, I really like your idea of mirroring chroot's behavior, I think that's the right way to go.  It also makes documentation easy, 'see also chroot's exit status' :D

This will make testing efforts easier as well, since we can quickly/easily distinguish problems coming from docker or the container.

Comment 6 Daniel Walsh 2014-06-27 19:24:22 UTC
Please comment on the issues

Comment 8 Chris Evich 2015-01-27 17:15:30 UTC
Just to clarify:

This bug is strictly for the run sub-command, since it needs special treatment. This issue is pretty important IMHO.

Bug 1162807 is about non-run sub-commands, It's verified fixed in 1.4.1-25.

Bug 1097334 is for all sub-commands not using consistent language in error/warning messages.  Minor issue.

Comment 10 Daniel Walsh 2015-04-14 19:55:00 UTC
shishir is this working in docker-1.6?

Comment 12 Sally 2015-07-07 18:52:58 UTC
*** Bug 1097334 has been marked as a duplicate of this bug. ***

Comment 15 Sally 2015-09-03 08:33:58 UTC
There is a pending PR for this, https://github.com/docker/docker/pull/14012.  The PR has gotten positive response, waiting for merge.

Comment 19 Daniel Walsh 2015-12-01 21:52:56 UTC
Fixed in docker-1.10/

Comment 20 Chris Evich 2015-12-02 16:36:32 UTC
Added note to https://trello.com/c/wK1SIihn for CI testing.

Comment 26 Daniel Walsh 2016-03-22 17:00:09 UTC
Yes lets wait for docker-1.10 to say this is fixed.

Comment 29 Luwen Su 2016-05-02 09:27:11 UTC
In docker-latest-1.10.3-19.el7.x86_64, there is a group of specified error code
see https://github.com/docker/docker/pull/14012/files,

Note:Use ``docker-latest`` instead of ``docker``

# docker-latest run this_image_does_not_exist /bin/false; echo $?
Unable to find image 'this_image_does_not_exist:latest' locally
Trying to pull repository docker.io/library/this_image_does_not_exist ... 
Pulling repository docker.io/library/this_image_does_not_exist
Error: image library/this_image_does_not_exist not found
docker: Error: image library/this_image_does_not_exist not found.
See 'docker-latest run --help'.
125

# docker-latest run busybox /etc; echo $?
exec: "/etc": permission denied
docker: Error response from daemon: Container command could not be invoked..
126

# docker-latest run busybox foo; echo $?
exec: "foo": executable file not found in $PATH
docker: Error response from daemon: Container command not found or does not exist..
127

# docker-latest run busybox /bin/sh -c 'exit 3' 
# echo $?
3

Comment 30 Chris Evich 2016-05-02 14:04:45 UTC
FYI there is still some minor inconsistent behaviour: ref: bug 1331575

Comment 32 errata-xmlrpc 2016-05-12 14:52:52 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHEA-2016-1057.html