docker/cli · error

no such service: {service}

Error message

no such service: {service}

What it means

In `runPS()` (ps.go:79-81), after successfully listing and printing tasks for the services that WERE found, the function checks if the `notfound` slice is non-empty and returns the joined error strings. This path is reached from `createFilter()` which returns `(filter, notfound, nil)` when at least one service matched (`serviceCount > 0`) but one or more did not. The error message format is `"no such service: <input>"` per missing service (constructed at line 134), joined with newlines if multiple. Tasks for the found services are still printed before the error is returned.

Source

Thrown at cli/command/service/ps.go:80

	}

	tasks, err := apiClient.TaskList(ctx, client.TaskListOptions{Filters: filter})
	if err != nil {
		return err
	}

	format := options.format
	if len(format) == 0 {
		format = task.DefaultFormat(dockerCli.ConfigFile(), options.quiet)
	}
	if options.quiet {
		options.noTrunc = true
	}
	if err := task.Print(ctx, dockerCli, tasks, idresolver.New(apiClient, options.noResolve), !options.noTrunc, options.quiet, format); err != nil {
		return err
	}
	if len(notfound) != 0 {
		return errors.New(strings.Join(notfound, "\n"))
	}
	return nil
}

func createFilter(ctx context.Context, apiClient client.APIClient, options psOptions) (client.Filters, []string, error) {
	filter := options.filter.Value()

	serviceIDFilter := make(client.Filters)
	serviceNameFilter := make(client.Filters)
	for _, service := range options.services {
		serviceIDFilter.Add("id", service)
		serviceNameFilter.Add("name", service)
	}
	serviceByID, err := apiClient.ServiceList(ctx, client.ServiceListOptions{Filters: serviceIDFilter})
	if err != nil {
		return filter, nil, err
	}
	serviceByName, err := apiClient.ServiceList(ctx, client.ServiceListOptions{Filters: serviceNameFilter})

View on GitHub (pinned to 4f84911bfe)

Solutions

  1. Verify each service name/ID exists before passing it: `docker service ls --filter name=<name>`
  2. Remove the non-existent service reference from the command arguments
  3. Use full service IDs instead of prefixes to avoid ambiguity and not-found issues

Example fix

# before
docker service ps web-service typo-service
# (tasks for web-service shown, then error: no such service: typo-service)

# after
docker service ps web-service

# or verify first
docker service ls --filter name=typo-service
Defensive patterns

Strategy: validation

Validate before calling

// Before calling runPS, verify all services exist
func validateServicesExist(ctx context.Context, c client.APIClient, services []string) ([]string, error) {
    var missing []string
    for _, svc := range services {
        _, err := c.ServiceInspect(ctx, svc, client.ServiceInspectOptions{})
        if errdefs.IsNotFound(err) {
            missing = append(missing, svc)
        }
    }
    if len(missing) > 0 {
        return missing, fmt.Errorf("services not found: %s", strings.Join(missing, ", "))
    }
    return nil, nil
}

Prevention

When it happens

Trigger: Running `docker service ps myservice nonexistent-service` where `myservice` exists but `nonexistent-service` does not. The tasks for `myservice` are listed, then the error for `nonexistent-service` is returned with exit code 1. Also triggered by a partial ID prefix match that doesn't resolve to any service.

Common situations: A script passes a list of service names/IDs where one has a typo or was deleted. The operator sees tasks for found services but also gets the error.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/fd60ca8c09c9dee4. Report an issue: GitHub.