Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`docker exec $CID false' does not set exit value to 1 #8703

Closed
gdm85 opened this issue Oct 22, 2014 · 9 comments · Fixed by #9208
Closed

`docker exec $CID false' does not set exit value to 1 #8703

gdm85 opened this issue Oct 22, 2014 · 9 comments · Fixed by #9208

Comments

@gdm85
Copy link
Contributor

gdm85 commented Oct 22, 2014

I am experiencing a weird issue with 1.3: exit value is always 0, regardless of command executed.

For example, running this script:

#!/bin/bash
CID=test-ev
docker run -d --name=$CID ubuntu:14.04 sh -c 'exec sleep 6000' || exit $?
docker exec $CID false
echo "docker exec: Exit value is $? (1 expected)"

The output is:

7e57bd4a32c168fc8ed9f23ef80737727984bbc4a8587d323109a2a5a53cef67
docker exec: Exit value is 0 (1 expected)

To verify that this problem is Docker-only, make same test with ssh or nsenter (my fork), that correctly return exit value 1.

I am right now looking up the code, as I have some clues about what could be happening, and will report later.

Update: I am using native driver. The log correctly reports the exit status:

[debug] exec.go:282 Exec task in container 4f555c8486f503fbfa8509f18c6f0fb17759b6d1161fc5f8b8ad7e8facc72bb1 exited with code 1

Update 2: I realize this is more a feature request rather than a bug: the "exec" operation is successful, but I believe users expect docker cli to fail with same exit code as container's process

@gdm85
Copy link
Contributor Author

gdm85 commented Oct 22, 2014

I found why the exit code is not 1: to do this you would have to reengineer the engine.Handler or engine.Status types to allow a payload.

Alternatives? An option to export the exit code to an environment variable (on host)?

I am sorry but as it is it's not much usable (without other hacks) and I actually will keep using nsenter

@SvenDowideit
Copy link
Contributor

@gdm85
Copy link
Contributor Author

gdm85 commented Oct 24, 2014

@SvenDowideit thanks for cross-linking it :)

It will take a bit of efforts to create a pull request, as first it's needed to refactor how the engine handles results. I am not writing one at the moment, both because I can use nsenter and because I was waiting for more Docker developers feedback.

@LK4D4
Copy link
Contributor

LK4D4 commented Oct 24, 2014

We have similar code for run. We need to implement some more endpoints for exec, which is not very hard, but very boring.

@irachex
Copy link
Contributor

irachex commented Oct 29, 2014

+1 docker exec should proxy exit code

@mkoval
Copy link

mkoval commented Nov 3, 2014

+1. Has anyone found a good workaround for this in the meantime? Is the docker-enter command provided by nsenter, linked to by @gdm85, effectively a drop-in replacement?

@gdm85
Copy link
Contributor Author

gdm85 commented Nov 3, 2014

@mkoval I use that as an SSH-like drop-in replacement, and I better customized the shell environment second my needs

@dougrad
Copy link

dougrad commented Nov 7, 2014

+1

duglin pushed a commit to duglin/docker that referenced this issue Nov 18, 2014
Closes moby#8703

Also made it so that when "docker exec" is run with -d (detached mode)
it'll print the id of the exec to the screen like "docker run -d" does
so people can query it via:
    curl http://.../exec/{id}/json

Signed-off-by: Doug Davis <dug@us.ibm.com>
dqminh pushed a commit to dqminh/moby that referenced this issue Nov 24, 2014
Closes moby#8703

Also made it so that when "docker exec" is run with -d (detached mode)
it'll print the id of the exec to the screen like "docker run -d" does
so people can query it via:
    curl http://.../exec/{id}/json

Signed-off-by: Doug Davis <dug@us.ibm.com>
duglin pushed a commit to duglin/docker that referenced this issue Nov 26, 2014
Note - only support the non-detached mode of exec right now.
Another PR will add -d support.

Closes moby#8703

Signed-off-by: Doug Davis <dug@us.ibm.com>
mapuri pushed a commit to mapuri/docker that referenced this issue Dec 4, 2014
Note - only support the non-detached mode of exec right now.
Another PR will add -d support.

Closes moby#8703

Signed-off-by: Doug Davis <dug@us.ibm.com>
duglin pushed a commit to duglin/docker that referenced this issue Feb 4, 2015
Closes moby#8703

Also made it so that when "docker exec" is run with -d (detached mode)
it'll print the id of the exec to the screen like "docker run -d" does
so people can query it via:
    curl http://.../exec/{id}/json

Signed-off-by: Doug Davis <dug@us.ibm.com>
@juniartisu
Copy link

Is this exec return code always 0 works now?
If so where can I get the fix? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants