diff --git a/cli/cmd/compose/up.go b/cli/cmd/compose/up.go index 5c11d2a9..7feb5a4f 100644 --- a/cli/cmd/compose/up.go +++ b/cli/cmd/compose/up.go @@ -274,21 +274,26 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro queue: queue, } + signalChan := make(chan os.Signal, 1) + signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) stopFunc := func() error { ctx := context.Background() _, err := progress.Run(ctx, func(ctx context.Context) (string, error) { + go func() { + <-signalChan + c.ComposeService().Kill(ctx, project, compose.KillOptions{}) // nolint:errcheck + }() + return "", c.ComposeService().Stop(ctx, project, compose.StopOptions{}) }) return err } - signalChan := make(chan os.Signal, 1) - signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) go func() { <-signalChan queue <- compose.ContainerEvent{ Type: compose.UserCancel, } - fmt.Println("Gracefully stopping...") + fmt.Println("Gracefully stopping... (press Ctrl+C again to force)") stopFunc() // nolint:errcheck }() diff --git a/local/compose/attach.go b/local/compose/attach.go index fe0bebc2..e8d82e60 100644 --- a/local/compose/attach.go +++ b/local/compose/attach.go @@ -83,7 +83,7 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis s.attachContainer(ctx, container, listener, project) // nolint: errcheck delete(crashed, event.Container) - s.waitContainer(ctx, container, listener) + s.waitContainer(container, listener) } return nil }, diff --git a/local/compose/start.go b/local/compose/start.go index b15785d9..51887397 100644 --- a/local/compose/start.go +++ b/local/compose/start.go @@ -51,14 +51,14 @@ func (s *composeService) Start(ctx context.Context, project *types.Project, opti for _, c := range containers { c := c go func() { - s.waitContainer(ctx, c, options.Attach) + s.waitContainer(c, options.Attach) }() } return nil } -func (s *composeService) waitContainer(ctx context.Context, c moby.Container, listener compose.ContainerEventListener) { - statusC, errC := s.apiClient.ContainerWait(ctx, c.ID, container.WaitConditionNotRunning) +func (s *composeService) waitContainer(c moby.Container, listener compose.ContainerEventListener) { + statusC, errC := s.apiClient.ContainerWait(context.Background(), c.ID, container.WaitConditionNotRunning) name := getContainerNameWithoutProject(c) select { case status := <-statusC: