diff --git a/cmd/compose/ps.go b/cmd/compose/ps.go index 0cf9b91656c..bbac59bf5ea 100644 --- a/cmd/compose/ps.go +++ b/cmd/compose/ps.go @@ -96,6 +96,16 @@ func runPs(ctx context.Context, streams api.Streams, backend api.Service, servic if err != nil { return err } + + if project != nil && len(services) > 0 { + names := project.ServiceNames() + for _, service := range services { + if !utils.StringContains(names, service) { + return fmt.Errorf("no such service: %s", service) + } + } + } + containers, err := backend.Ps(ctx, name, api.PsOptions{ Project: project, All: opts.All, @@ -112,7 +122,6 @@ SERVICES: continue SERVICES } } - return fmt.Errorf("no such service: %s", s) } if len(opts.Status) != 0 {