0

When I run a docker CLI command and send a SIGTERM signal to the process running the docker command, I would expect the process to exit with status 143 representing the SIGTERM but it actually exits with status 1. Why is this the case?

(shell 1)
$ docker run -it --rm alpine:latest sleep 1000

(shell 2)
$ ps | grep docker
75658 ttys000    0:00.03 docker run -it --rm alpine:latest sleep 1000

(shell 2)
$ kill -SIGTERM 75658

(shell 1)
...container stops running
$ echo $?
1 (was expecting 143)

On the other hand, it returns with the expected status (137) when I end the process with a SIGKILL.

1 Answer 1

1

You didn't kill the sleep command, you killed the docker CLI:

$ ps -ef | grep sleep
bmitch    949110   10662  0 14:26 pts/11   00:00:00 docker run -it --rm alpine:latest sleep 1000
root      949193  949173  0 14:26 pts/0    00:00:00 sleep 1000
bmitch    949223   10618  0 14:27 pts/10   00:00:00 grep sleep

Which means killing the docker process just exits the command, the container is still running and there's no exit code passed through:

$ docker run -it --rm alpine:latest sleep 1000
context canceled

# the above message appears after running a kill -SIGTERM 949110 command in another terminal

$ docker ps -l
CONTAINER ID   IMAGE           COMMAND        CREATED          STATUS          PORTS     NAMES
e62c8f6d2424   alpine:latest   "sleep 1000"   21 seconds ago   Up 21 seconds             awesome_morse

The sleep command itself doesn't respond to SIGTERM for me, but it does respond to SIGKILL:

$ docker run -it --rm alpine:latest sleep 1000

# from another terminal, kill the sleep process itself
# this requires sudo since it is running as root

$ echo $?
137
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.