mirror of https://github.com/docker/compose.git
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 <jaime.soriano@elastic.co>
This commit is contained in:
parent
b032999f06
commit
5c1e5f3fc7
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue