mirror of https://github.com/docker/compose.git
only stop/remove selected services
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
d86649140f
commit
5cead2266d
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue