mirror of https://github.com/docker/compose.git
forward signal to container
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
419fcdd6c8
commit
fed8ef6b79
|
@ -19,6 +19,8 @@ package compose
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/docker/cli/cli"
|
||||
|
@ -38,6 +40,14 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
|
|||
start.Attach = !opts.Detach
|
||||
start.Containers = []string{containerID}
|
||||
|
||||
// remove cancellable context signal handler so we can forward signals to container without compose to exit
|
||||
signal.Reset()
|
||||
|
||||
sigc := make(chan os.Signal, 128)
|
||||
signal.Notify(sigc)
|
||||
go cmd.ForwardAllSignals(ctx, s.dockerCli, containerID, sigc)
|
||||
defer signal.Stop(sigc)
|
||||
|
||||
err = cmd.RunStart(s.dockerCli, &start)
|
||||
if sterr, ok := err.(cli.StatusError); ok {
|
||||
return sterr.StatusCode, nil
|
||||
|
|
Loading…
Reference in New Issue