-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Signal to stop a container. #15307
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
Signal to stop a container. #15307
Conversation
c62a252 to
5acf54d
Compare
|
Seems ok to me. |
man/docker-run.1.md
Outdated
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.
Here it's --stop-signal, but everywhere else it's --kill-signal.
Also, personally I prefer --stop-signal over --kill-signal. Since docker sends a SIGKILL after the 10 second timeout, calling this "kill-signal" makes it confusing which signal this is controlling.
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.
I actually prefer stop-signal too, that was the first implementation and that's why the doc still mentions it. For other conversations it seemed better to call it kill-signal, but I'm open to change it back.
/cc @crosbymichael
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.
also wondering if we need a short-hand (-s) flag for this; will this be a frequently enough used option? (we're running out of letters fast :-))
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.
we don't need it
|
Not sure we should be checking for proper signals on this. Since the signal table seems to be often out of date. |
I think we could support both. I agree that we might not include all the signals in our table, but remembering a signal name is easier than remembering a number in some cases. I think we should check if the flag is a number and pass it through in that case. |
3fd6d37 to
6781c4b
Compare
|
Ok, as long as we support numbers. |
|
Design LGTM. |
daemon/container.go
Outdated
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.
Why not syscall.SIGTERM here?
ad648b1 to
1064d35
Compare
9adc7c6 to
4ceb9e1
Compare
Allow to set the signal to stop a container in `docker run`: - Use `--stop-signal` with docker-run to set the default signal the container will use to exit. Signed-off-by: David Calavera <[email protected]>
This way, images creators can set the exit signal their programs use. Signed-off-by: David Calavera <[email protected]>
3c2ab44 to
3781cde
Compare
|
@SvenDowideit, @moxiegirl Please, take a look. |
|
@calavera given the addition to the Dockerfile syntax, does this need wider approval before merging? I saw some concerns raised on the build-ARGS PR (which was approved before the freeze on builder) |
|
@thaJeztah we already went through that |
|
LGTM |
|
Nice one! |
|
Can I use a custom command replace signal ? |
|
You could docker exec into the container to execute this. docker exec CONTAINID solr stop |
|
Using the atomic command you can add a STOP label which would execute this command |
|
@rhatdan yes,I know I can use How can I use STOP label ?Can you give me a example?Thanks |
|
@loveai88 Docker starts a process, it interacts with that process by using standard unix signals. |
|
atomic command is a wrapper around docker that uses LABEL embedded in the container image to tell it how to start, stop, install, uninstall, scan, verify ... the images. Here are the generic Labels that atomic command and others can use. Basically you could add a label in your dockerfile. LABEL STOP docker exec ${NAME} solr stop Then users could execute Similarly if you wanted a special |
|
@rhatdan 👍 |
| complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l rm -d 'Automatically remove the container when it exits (incompatible with -d)' | ||
| complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l security-opt -d 'Security Options' | ||
| complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l sig-proxy -d 'Proxy received signals to the process (non-TTY mode only). SIGCHLD, SIGSTOP, and SIGKILL are not proxied.' | ||
| complete -c docker -A -f -n '__fish_seen_subcommand_from run' -l stop-signal 'Signal to kill a container' |
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.
to kill or stop?
| stopSignal, _ = signal.ParseSignal(container.Config.StopSignal) | ||
| } | ||
|
|
||
| if int(stopSignal) == 0 { | ||
| stopSignal, _ = signal.ParseSignal(signal.DefaultStopSignal) |
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.
🙈 signal.ParseSignal returns -1 if the signal is invalid; the branch above doesn't check the error, and this branch only checks for 0, so this can return -1 as signal;
docker run. Use--stop-signalwith docker-run to set the default signal the container will use to exit.STOPcommand to the builder to allow image creator to set the default exit signal for their programs.TODO:
Closes #6711
Signed-off-by: David Calavera [email protected]