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

  1. List what exists: `docker compose ps -a` (or the containers API) and correct the service name
  2. If the service should exist, bring it up first (`docker compose up -d <svc>`) including any required `--profile`
  3. 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

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


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/55deb76067ae7f79. Report an issue: GitHub.