diff --git a/pkg/api/api.go b/pkg/api/api.go index ff503d25..31095ac8 100644 --- a/pkg/api/api.go +++ b/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 diff --git a/pkg/compose/containers.go b/pkg/compose/containers.go index cd75eeff..3eb0270d 100644 --- a/pkg/compose/containers.go +++ b/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 diff --git a/pkg/compose/kill.go b/pkg/compose/kill.go index ca7039ce..9cface85 100644 --- a/pkg/compose/kill.go +++ b/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 } diff --git a/pkg/compose/up.go b/pkg/compose/up.go index dcc97b47..9615d9e0 100644 --- a/pkg/compose/up.go +++ b/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