Skip to content

Conversation

@calavera
Copy link
Contributor

@calavera calavera commented Aug 4, 2015

  • 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.
  • Add STOP command to the builder to allow image creator to set the default exit signal for their programs.

TODO:

  • Tests
  • More docs
  • Shell completions

Closes #6711

Signed-off-by: David Calavera [email protected]

@calavera calavera closed this Aug 4, 2015
@calavera calavera reopened this Aug 4, 2015
@calavera calavera changed the title Stop signal to kill a container. [WIP] Stop signal to kill a container. Aug 4, 2015
@calavera calavera changed the title [WIP] Stop signal to kill a container. [WIP] Signal to kill a container. Aug 4, 2015
@calavera calavera force-pushed the stop_signal branch 2 times, most recently from c62a252 to 5acf54d Compare August 4, 2015 22:53
@cpuguy83
Copy link
Member

cpuguy83 commented Aug 5, 2015

Seems ok to me.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Member

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 :-))

Copy link
Contributor Author

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

@rhatdan
Copy link
Contributor

rhatdan commented Aug 6, 2015

Not sure we should be checking for proper signals on this. Since the signal table seems to be often out of date.

@calavera
Copy link
Contributor Author

calavera commented Aug 6, 2015

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.

@calavera calavera changed the title [WIP] Signal to kill a container. [WIP] Signal to stop a container. Aug 6, 2015
@calavera calavera force-pushed the stop_signal branch 2 times, most recently from 3fd6d37 to 6781c4b Compare August 6, 2015 21:13
@rhatdan
Copy link
Contributor

rhatdan commented Aug 7, 2015

Ok, as long as we support numbers.

@icecrime
Copy link
Contributor

icecrime commented Aug 8, 2015

Design LGTM.

Copy link
Contributor

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?

@calavera calavera force-pushed the stop_signal branch 3 times, most recently from ad648b1 to 1064d35 Compare August 10, 2015 15:16
@calavera calavera force-pushed the stop_signal branch 2 times, most recently from 9adc7c6 to 4ceb9e1 Compare August 11, 2015 01:12
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]>
@calavera
Copy link
Contributor Author

@SvenDowideit, @moxiegirl Please, take a look.

@thaJeztah
Copy link
Member

@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)

@calavera
Copy link
Contributor Author

@thaJeztah we already went through that

@moxiegirl
Copy link
Contributor

LGTM

calavera added a commit that referenced this pull request Sep 11, 2015
@calavera calavera merged commit db54c79 into moby:master Sep 11, 2015
@calavera calavera deleted the stop_signal branch September 11, 2015 16:25
@phemmer phemmer mentioned this pull request Sep 22, 2015
@SamSaffron
Copy link

Nice one!

@JadeQin
Copy link

JadeQin commented Jan 14, 2016

Can I use a custom command replace signal ?
for example use ./bin/solr stop to stop a solr container

@rhatdan
Copy link
Contributor

rhatdan commented Jan 14, 2016

You could docker exec into the container to execute this.

docker exec CONTAINID solr stop

@rhatdan
Copy link
Contributor

rhatdan commented Jan 14, 2016

Using the atomic command you can add a STOP label which would execute this command

@JadeQin
Copy link

JadeQin commented Jan 15, 2016

@rhatdan yes,I know I can use exec to do it. Docker has a default start command,why not have a default stop command?

How can I use STOP label ?Can you give me a example?Thanks

@cpuguy83
Copy link
Member

@loveai88 Docker starts a process, it interacts with that process by using standard unix signals.
I'd recommend using something like runit (or even a custom bash script, really) which allow you to specify these things.

@rhatdan
Copy link
Contributor

rhatdan commented Jan 15, 2016

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.
https://github.com/projectatomic/atomic

Here are the generic Labels that atomic command and others can use.
https://github.com/projectatomic/ContainerApplicationGenericLabels

Basically you could add a label in your dockerfile.

LABEL STOP docker exec ${NAME} solr stop

Then users could execute

atomic stop CONTAINERID
atomic would execute this command.

Similarly if you wanted a special

@JadeQin
Copy link

JadeQin commented Jan 15, 2016

@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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to kill or stop?

Comment on lines +1148 to +1152
stopSignal, _ = signal.ParseSignal(container.Config.StopSignal)
}

if int(stopSignal) == 0 {
stopSignal, _ = signal.ParseSignal(signal.DefaultStopSignal)
Copy link
Member

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.