mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
make docker run handle SIGINT/SIGTERM
This commit is contained in:
parent
e3be2e959b
commit
df86cb9a5c
1 changed files with 15 additions and 0 deletions
15
commands.go
15
commands.go
|
@ -1393,6 +1393,21 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||
v.Set("stderr", "1")
|
||||
}
|
||||
|
||||
signals := make(chan os.Signal, 1)
|
||||
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
||||
go func() {
|
||||
for {
|
||||
sig := <-signals
|
||||
if sig == syscall.SIGINT || sig == syscall.SIGTERM {
|
||||
fmt.Printf("\nReceived signal: %s; cleaning up\n", sig)
|
||||
if err := cli.CmdStop("-t", "4", runResult.ID); err != nil {
|
||||
fmt.Printf("failed to stop container:", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if err := cli.hijack("POST", "/containers/"+runResult.ID+"/attach?"+v.Encode(), config.Tty, cli.in, cli.out); err != nil {
|
||||
utils.Debugf("Error hijack: %s", err)
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue