docker/compose · error
no such service: %s
Error message
no such service: %s
What it means
When a compose project could be loaded, `docker compose ps` validates each requested positional service name against the project's declared services and rejects any name not present in the compose file. Only when no project can be resolved does it skip this check.
Source
Thrown at cmd/compose/ps.go:106
flags.BoolVar(&opts.Services, "services", false, "Display services")
flags.BoolVar(&opts.Orphans, "orphans", true, "Include orphaned services (not declared by project)")
flags.BoolVarP(&opts.All, "all", "a", false, "Show all stopped containers (including those created by the run command)")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output")
return psCmd
}
func runPs(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, services []string, opts psOptions) error { //nolint:gocyclo
project, name, err := opts.projectOrName(ctx, dockerCli, services...)
if err != nil {
return err
}
if project != nil {
names := project.ServiceNames()
if len(services) > 0 {
for _, service := range services {
if !slices.Contains(names, service) {
return fmt.Errorf("no such service: %s", service)
}
}
} else if !opts.Orphans {
// until user asks to list orphaned services, we only include those declared in project
services = names
}
}
backend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)
if err != nil {
return err
}
containers, err := backend.Ps(ctx, name, api.PsOptions{
Project: project,
All: opts.All || len(opts.Status) != 0,
Services: services,
})
if err != nil {View on GitHub (pinned to ddc4b044b6)
Solutions
- List available services with `docker compose config --services` and correct the name.
- Ensure the right compose files are loaded (`-f`, `COMPOSE_FILE`, working directory) so the service is actually defined.
- Derive service names in scripts from `docker compose config --services` instead of hardcoding.
Example fix
# before docker compose ps webapp # service was renamed to api # after docker compose config --services docker compose ps api
Defensive patterns
Strategy: validation
Validate before calling
# bash: verify requested services exist before ps
mapfile -t DEFINED < <(docker compose config --services)
for want in "$@"; do
printf '%s\n' "${DEFINED[@]}" | grep -qx "$want" || { echo "no such service: $want" >&2; exit 2; }
done
docker compose ps "$@" Prevention
- Generate service lists from `docker compose config --services` in scripts.
- After renaming services, grep CI for the old names.
When it happens
Trigger: Running `docker compose ps typo-name` where the compose file defines other services; using an old service name after it was renamed in the file; querying a service defined only in an override file that isn't included.
Common situations: Renamed or removed services in a refactor; wrong -f file selection so the intended service isn't defined; CI scripts hardcoding service names that drift from the compose file.
Related errors
- arguments to --filter should be in form KEY=VAL
- source can not be empty
- destination can not be empty
- invalid filter '${filter}'
- --index requires one service to be selected
AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15).
Data as JSON: /api/errors/848935f6a9f3ee63.
Report an issue: GitHub.