docker/compose · error · api.ErrNotFound
no such service: %q: %w
Error message
no such service: %q: %w
What it means
After projectFromName builds its service set from observed containers, it validates each requested service name against that set; an unknown name yields this error wrapping api.ErrNotFound. The check runs before WithSelectedServices, so it only sees services that actually have containers — a service present in the file but never started is 'unknown' here.
Source
Thrown at pkg/compose/compose.go:417
if len(dcArr) > 2 {
restart, _ = strconv.ParseBool(dcArr[2])
}
}
service.DependsOn[dependency] = types.ServiceDependency{Condition: condition, Restart: restart, Required: required}
}
set[name] = service
}
}
project.Services = set
SERVICES:
for _, qs := range services {
for _, es := range project.Services {
if es.Name == qs {
continue SERVICES
}
}
return project, fmt.Errorf("no such service: %q: %w", qs, api.ErrNotFound)
}
project, err := project.WithSelectedServices(services)
if err != nil {
return project, err
}
return project, nil
}
func increment(scale *int) *int {
i := 1
if scale != nil {
i = *scale + 1
}
return &i
}
func (s *composeService) actualVolumes(ctx context.Context, projectName string) (types.Volumes, error) {View on GitHub (pinned to ddc4b044b6)
Solutions
- List what exists: `docker compose ps -a` (or the containers API) and correct the service name
- If the service should exist, bring it up first (`docker compose up -d <svc>`) including any required `--profile`
- For API consumers, validate requested names against projectFromName's derived set before dispatching
Example fix
# before docker compose exec webs sh # typo # after docker compose exec web sh
Defensive patterns
Strategy: validation
Validate before calling
existing := map[string]bool{}
for _, c := range containers { existing[c.Labels[api.ServiceLabel]] = true }
for _, name := range requestedServices {
if !existing[name] {
return fmt.Errorf("service %q has no containers in project", name)
}
} Try / catch
if err != nil && errors.Is(err, api.ErrNotFound) {
// unknown service: verify spelling/profiles against `docker compose ps -a` before retrying
} Prevention
- Derive service names from the project model rather than hardcoding strings in scripts
- Remember profiles: a service in an inactive profile has no runtime containers
When it happens
Trigger: Calling runtime-derived APIs with a service name that has no containers under the project: `docker compose stop|rm|exec|logs <svc>` for a service not created yet, a typo, or one activated only under an inactive profile.
Common situations: Typos in service names in scripts; services gated behind profiles (`--profile` not passed during up, so the service was never created); scaled-in services whose containers were removed; mixing service names across multiple compose files in one directory.
Related errors
- no container found for project %q: %w
- 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/55deb76067ae7f79.
Report an issue: GitHub.