Bläddra i källkod

docker compose up always kills the containers on second Ctrl-C

Kill executed on the second Ctrl-C of docker compose up  was
filtering containers depending on its state. In some cases the
containers can reach an state for what these filters don't get
any container, and the command keeps reporting `no container to
kill`.

Remove this filtering, so it tries to kill any container it
finds, independently of its state.

Fixes https://github.com/docker/compose/issues/10661

Signed-off-by: Jaime Soriano Pastor <[email protected]>
Jaime Soriano Pastor 1 år sedan
förälder
incheckning
5c1e5f3fc7
4 ändrade filer med 8 tillägg och 5 borttagningar
  1. 2 0
      pkg/api/api.go
  2. 4 4
      pkg/compose/containers.go
  3. 1 1
      pkg/compose/kill.go
  4. 1 0
      pkg/compose/up.go

+ 2 - 0
pkg/api/api.go

@@ -312,6 +312,8 @@ type KillOptions struct {
 	Services []string
 	// Signal to send to containers
 	Signal string
+	// All can be set to true to try to kill all found containers, independently of their state
+	All bool
 }
 
 // RemoveOptions group options of the Remove API

+ 4 - 4
pkg/compose/containers.go

@@ -41,12 +41,12 @@ const (
 	oneOffOnly
 )
 
-func (s *composeService) getContainers(ctx context.Context, project string, oneOff oneOff, stopped bool, selectedServices ...string) (Containers, error) {
+func (s *composeService) getContainers(ctx context.Context, project string, oneOff oneOff, all bool, selectedServices ...string) (Containers, error) {
 	var containers Containers
 	f := getDefaultFilters(project, oneOff, selectedServices...)
 	containers, err := s.apiClient().ContainerList(ctx, containerType.ListOptions{
 		Filters: filters.NewArgs(f...),
-		All:     stopped,
+		All:     all,
 	})
 	if err != nil {
 		return nil, err
@@ -73,7 +73,7 @@ func getDefaultFilters(projectName string, oneOff oneOff, selectedServices ...st
 	return f
 }
 
-func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName string, oneOff oneOff, stopped bool, serviceName string, containerIndex int) (moby.Container, error) {
+func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName string, oneOff oneOff, all bool, serviceName string, containerIndex int) (moby.Container, error) {
 	defaultFilters := getDefaultFilters(projectName, oneOff, serviceName)
 	if containerIndex > 0 {
 		defaultFilters = append(defaultFilters, containerNumberFilter(containerIndex))
@@ -82,7 +82,7 @@ func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName
 		Filters: filters.NewArgs(
 			defaultFilters...,
 		),
-		All: stopped,
+		All: all,
 	})
 	if err != nil {
 		return moby.Container{}, err

+ 1 - 1
pkg/compose/kill.go

@@ -40,7 +40,7 @@ func (s *composeService) kill(ctx context.Context, projectName string, options a
 	services := options.Services
 
 	var containers Containers
-	containers, err := s.getContainers(ctx, projectName, oneOffInclude, false, services...)
+	containers, err := s.getContainers(ctx, projectName, oneOffInclude, options.All, services...)
 	if err != nil {
 		return err
 	}

+ 1 - 0
pkg/compose/up.go

@@ -122,6 +122,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
 						return s.Kill(context.Background(), project.Name, api.KillOptions{
 							Services: options.Create.Services,
 							Project:  project,
+							All:      true,
 						})
 					})
 					return nil