diff --git a/api/compose/api.go b/api/compose/api.go index 3014401fe..066d39b9e 100644 --- a/api/compose/api.go +++ b/api/compose/api.go @@ -126,6 +126,8 @@ type RestartOptions struct { type StopOptions struct { // Timeout override container stop timeout Timeout *time.Duration + // Services passed in the command line to be stopped + Services []string } // UpOptions group options of the Up API @@ -187,6 +189,8 @@ type RemoveOptions struct { Volumes bool // Force don't ask to confirm removal Force bool + // Services passed in the command line to be removed + Services []string } // RunOptions group options of the Run API diff --git a/cli/cmd/compose/images.go b/cli/cmd/compose/images.go index edcf8b07e..76bd03ea7 100644 --- a/cli/cmd/compose/images.go +++ b/cli/cmd/compose/images.go @@ -32,7 +32,7 @@ import ( "github.com/docker/compose-cli/utils" "github.com/docker/docker/pkg/stringid" - units "github.com/docker/go-units" + "github.com/docker/go-units" ) type imageOptions struct { diff --git a/cli/cmd/compose/remove.go b/cli/cmd/compose/remove.go index 753f8300a..9f3814384 100644 --- a/cli/cmd/compose/remove.go +++ b/cli/cmd/compose/remove.go @@ -73,7 +73,9 @@ func runRemove(ctx context.Context, opts removeOptions, services []string) error if opts.stop { _, err = progress.Run(ctx, func(ctx context.Context) (string, error) { - err := c.ComposeService().Stop(ctx, project, compose.StopOptions{}) + err := c.ComposeService().Stop(ctx, project, compose.StopOptions{ + Services: services, + }) return "", err }) if err != nil { @@ -82,7 +84,8 @@ func runRemove(ctx context.Context, opts removeOptions, services []string) error } reosurces, err := c.ComposeService().Remove(ctx, project, compose.RemoveOptions{ - DryRun: true, + DryRun: true, + Services: services, }) if err != nil { return err diff --git a/cli/cmd/compose/stop.go b/cli/cmd/compose/stop.go index f80dc1c94..1884cf1bb 100644 --- a/cli/cmd/compose/stop.go +++ b/cli/cmd/compose/stop.go @@ -69,7 +69,8 @@ func runStop(ctx context.Context, opts stopOptions, services []string) error { } _, err = progress.Run(ctx, func(ctx context.Context) (string, error) { return "", c.ComposeService().Stop(ctx, project, compose.StopOptions{ - Timeout: timeout, + Timeout: timeout, + Services: services, }) }) return err diff --git a/local/compose/remove.go b/local/compose/remove.go index 1018bc34d..713077d2c 100644 --- a/local/compose/remove.go +++ b/local/compose/remove.go @@ -29,7 +29,12 @@ import ( ) func (s *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) ([]string, error) { - containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true) + services := options.Services + if len(services) == 0 { + services = project.ServiceNames() + } + + containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true, services...) if err != nil { return nil, err } diff --git a/local/compose/stop.go b/local/compose/stop.go index b528312db..0e950e440 100644 --- a/local/compose/stop.go +++ b/local/compose/stop.go @@ -27,8 +27,13 @@ import ( func (s *composeService) Stop(ctx context.Context, project *types.Project, options compose.StopOptions) error { w := progress.ContextWriter(ctx) + + services := options.Services + if len(services) == 0 { + services = project.ServiceNames() + } var containers Containers - containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true, project.ServiceNames()...) + containers, err := s.getContainers(ctx, project.Name, oneOffInclude, true, services...) if err != nil { return err }