From fed8ef6b791813f8b1479cf095a37cb4352fa02d Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 30 May 2023 15:16:22 +0200 Subject: [PATCH] forward signal to container Signed-off-by: Nicolas De Loof --- pkg/compose/run.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/compose/run.go b/pkg/compose/run.go index d0ae1b9ab..36fedbfaf 100644 --- a/pkg/compose/run.go +++ b/pkg/compose/run.go @@ -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