Skip to content

Commit 5c1e5f3

Browse files
jsorianondeloof
authored andcommitted
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 docker#10661 Signed-off-by: Jaime Soriano Pastor <[email protected]>
1 parent b032999 commit 5c1e5f3

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

pkg/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ type KillOptions struct {
312312
Services []string
313313
// Signal to send to containers
314314
Signal string
315+
// All can be set to true to try to kill all found containers, independently of their state
316+
All bool
315317
}
316318

317319
// RemoveOptions group options of the Remove API

pkg/compose/containers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ const (
4141
oneOffOnly
4242
)
4343

44-
func (s *composeService) getContainers(ctx context.Context, project string, oneOff oneOff, stopped bool, selectedServices ...string) (Containers, error) {
44+
func (s *composeService) getContainers(ctx context.Context, project string, oneOff oneOff, all bool, selectedServices ...string) (Containers, error) {
4545
var containers Containers
4646
f := getDefaultFilters(project, oneOff, selectedServices...)
4747
containers, err := s.apiClient().ContainerList(ctx, containerType.ListOptions{
4848
Filters: filters.NewArgs(f...),
49-
All: stopped,
49+
All: all,
5050
})
5151
if err != nil {
5252
return nil, err
@@ -73,7 +73,7 @@ func getDefaultFilters(projectName string, oneOff oneOff, selectedServices ...st
7373
return f
7474
}
7575

76-
func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName string, oneOff oneOff, stopped bool, serviceName string, containerIndex int) (moby.Container, error) {
76+
func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName string, oneOff oneOff, all bool, serviceName string, containerIndex int) (moby.Container, error) {
7777
defaultFilters := getDefaultFilters(projectName, oneOff, serviceName)
7878
if containerIndex > 0 {
7979
defaultFilters = append(defaultFilters, containerNumberFilter(containerIndex))
@@ -82,7 +82,7 @@ func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName
8282
Filters: filters.NewArgs(
8383
defaultFilters...,
8484
),
85-
All: stopped,
85+
All: all,
8686
})
8787
if err != nil {
8888
return moby.Container{}, err

pkg/compose/kill.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *composeService) kill(ctx context.Context, projectName string, options a
4040
services := options.Services
4141

4242
var containers Containers
43-
containers, err := s.getContainers(ctx, projectName, oneOffInclude, false, services...)
43+
containers, err := s.getContainers(ctx, projectName, oneOffInclude, options.All, services...)
4444
if err != nil {
4545
return err
4646
}

pkg/compose/up.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
122122
return s.Kill(context.Background(), project.Name, api.KillOptions{
123123
Services: options.Create.Services,
124124
Project: project,
125+
All: true,
125126
})
126127
})
127128
return nil

0 commit comments

Comments
 (0)