forward signal to container

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2023-05-30 15:16:22 +02:00 committed by Nicolas De loof
parent 419fcdd6c8
commit fed8ef6b79
1 changed files with 10 additions and 0 deletions

View File

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