Bug 1162807

Summary: Docker CLI exit codes for errors?
Product: Red Hat Enterprise Linux 7 Reporter: Chris Evich <cevich>
Component: dockerAssignee: smahajan <smahajan>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: high Docs Contact:
Priority: unspecified    
Version: 7.0CC: bsarathy, dwalsh, lsm5, mjenner, smahajan, virt-bugs
Target Milestone: rcKeywords: Extras, Reopened
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1097344 Environment:
Last Closed: 2015-03-05 03:19:07 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:

Description Chris Evich 2014-11-11 18:00:19 UTC
+++ This bug was initially created as a clone of Bug #1097344 +++

Description of problem:
Non-run docker CLI operations should return non-zero exit code along with error messages.  Alternatively, the "chroot" method here https://github.com/dotcloud/docker/issues/6734 would also be acceptable.

Version-Release number of selected component (if applicable):
docker-1.3.0-5.el7.HTB.x86_64

How reproducible:
Trivial

Steps to Reproduce:
1. # /usr/bin/docker -D attach --no-stdin=sig-proxy
2. # /usr/bin/docker -D commit --authormessage 123412341234 <container name>

Actual results:
Exit code: 0
Standard Out: """"""
Standard Error: """invalid boolean value "sig-proxy" for  --no-stdin: strconv.ParseBool: parsing "sig-proxy": invalid syntax
See 'docker attach --help'.
"""

Exit code: 0
Standard Out: """"""
Standard Error: """flag provided but not defined: --authormessage
See 'docker commit --help'.
"""

Expected results:
Exit code: <non-zero>
Standard Out: """"""
Standard Error: """invalid boolean value "sig-proxy" for  --no-stdin: strconv.ParseBool: parsing "sig-proxy": invalid syntax
See 'docker attach --help'.
"""

Exit code: <non-zero>
Standard Out: """"""
Standard Error: """flag provided but not defined: --authormessage
See 'docker commit --help'.
"""

Additional info:

Some CLI commands actually do return non-zero, for example:

# /usr/bin/docker -D load --input

Exit code: 1
Standard Out: """"""
Standard Error: """flag needs an argument: --input
See 'docker load --help'.
[2014-11-11T12:30:25.736050885-05:00] [fatal] log.go:64 flag needs an argument: --input
"""

Comment 2 smahajan@redhat.com 2014-11-21 20:38:39 UTC
These 3 commands are providing an exit code of 2 (Non-zero exit code for failure), so they are working as expected.

1) # /usr/bin/docker -D attach --no-stdin=sig-proxy
   echo $?
   Prints: 2
2. # /usr/bin/docker -D commit --authormessage 123412341234 <container name>
   echo $?
   Prints: 2
3) docker load --input
   Prints: flag needs an arguement: --input
   echo $?
   Prints: 2

however HELP commands are throwing non-zero (2) exit code.

e.g. docker --help
     docker run --help
     docker pull --help

These commands should throw exit code 0 (SUCCESS).
So I ll keep this ticket open for now.

Shishir

Comment 3 Daniel Walsh 2014-11-21 20:57:41 UTC
There is an existing pull request to fix the docker --help issue.

Comment 4 smahajan@redhat.com 2014-11-24 15:09:57 UTC
For --help issue this is the PR being worked on.
https://github.com/docker/docker/pull/9085

Closing the ticket now.

Shishir

Comment 5 Chris Evich 2014-11-24 16:15:25 UTC
Hi,

There must be some discrepancy or mistake I am making then.

[root@dockertest ~]# yum update
Loaded plugins: product-id, subscription-manager
No packages marked for update
[root@dockertest ~]# docker version
Client version: 1.3.0
Client API version: 1.15
Go version (client): go1.3.1
Git commit (client): 16a7d74/1.3.0
OS/Arch (client): linux/amd64
Server version: 1.3.0
Server API version: 1.15
Go version (server): go1.3.1
Git commit (server): 16a7d74/1.3.0

With docker-1.3.0-5.el7.HTB.x86_64 (i.e. CURRENTRELEASE) I'm still getting a zero exit code, even copy-paste from your commands above:

[root@dockertest ~]# /usr/bin/docker -D attach --no-stdin=sig-proxy; echo $?
invalid boolean value "sig-proxy" for  --no-stdin: strconv.ParseBool: parsing "sig-proxy": invalid syntax
See 'docker attach --help'.
0

[root@dockertest ~]# docker ps -a
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS                  PORTS               NAMES
7c110ce78697        docker_testimage:latest   "date"              3 days ago          Exited (0) 3 days ago                       test                

[root@dockertest ~]# /usr/bin/docker -D commit --authormessage 123412341234 test; echo $?
flag provided but not defined: --authormessage
See 'docker commit --help'.
0

Though "load" is now giving an exit code of "1", which is good:

[root@dockertest ~]# docker load --input; echo $?
flag needs an argument: --input
See 'docker load --help'.
[2014-11-24T11:07:10.287030860-05:00] [fatal] log.go:64 flag needs an argument: --input
1

Comment 6 Daniel Walsh 2014-11-24 16:30:17 UTC
Ok you guys are working off of different packages.    We need to test with the updated docker --help patch.  To see if we see the same problems.


shishir could you test with the patch I linked you to, to see if this is still a problem.

Comment 7 Chris Evich 2014-11-24 16:49:43 UTC
Thanks Dan, I'm glad it was just simple package mismatch.  Re-opening so QE can test candidate and/or verify in released/HTB package, including the "--help fix" (unless there's a separate BZ for that aspect).

Comment 9 Chris Evich 2014-12-12 17:16:43 UTC
Verified fixed with docker-1.3.2-4.el7.x86_64

Comment 15 Chris Evich 2015-03-04 15:26:18 UTC
Docker autotest exercizes & verifies command exit codes extensivly.

Comment 16 errata-xmlrpc 2015-03-05 03:19:07 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/RHSA-2015-0623.html