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
#507 - make docker run handle SIGINT/SIGTERM #1249
#507 - make docker run handle SIGINT/SIGTERM #1249
Conversation
I know this PR produce the right behaviour, but I think many people, myself included, are used to do ctrl-c to exit the client and not the process. I think we should add a hint somewhere the the keystroke combination to detach. ( I can't remember it, as I always use ctrl+c ;) ) Maybe we could have a longer timeout, but if you press a second time ctrc+c, it call cmdKill ? |
@vieux If you type ctrl-c, the signal will still be sent to the process you're running, e.g.: bash or something else. ctrl+p ctrl-q detaches and SIGINT is still handled by the process running in the container. SIGTERM/SIGINT has to be sent to the docker process itself in order to stop it. In my opinion, this PR only changes the behavior of the docker process spawned by Concerning the second signal, yes, we could do that. |
signals := make(chan os.Signal, 1) | ||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) | ||
go func() { | ||
for { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the for {
loop is not really necessary, is it?. The goroutine should wait for any of the signals in the line below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a reason for having the for, we want to ask the container to stop more than just once if SIGINT/SIGTERM is received more than once.
LGTM, /cc @vieux @crosbymichael |
LGTM |
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) | ||
go func() { | ||
for { | ||
sig := <-signals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to for sig := range signals {
.
I wanted to have signal handling very badly, so I wrote this little wrapper script, which handles INT/TERM/HUP and translates it to stop and restart. Have a look: https://github.com/lgierth/docker-exec I knew this PR here is in the works, but solving the problem with a wrapping shell script seemed like a fun thing to do. It might also take a bit of pressure off this PR, since anybody who badly wants this feature can just use the script, and then switch to the official support once this PR is released. |
LGTM |
1 similar comment
LGTM |
…ng_to_docker_run #507 - make docker run handle SIGINT/SIGTERM
This PR adds SIGTERM and SIGINT handling to docker run. When any of the two signals is received by a
docker run
process,docker stop
will be run to try to stop the container. If the container fails to stop graciously in 4 seconds, it's killed bydocker stop
.Observations:
docker stop
isn't called, the CmdStop function is called instead to avoid duplicating any code.Questions:
docker stop
?This PR fixes #507.