{"record":{"id":"55deb76067ae7f79","repo":"docker/compose","slug":"no-such-service-q-w","errorCode":null,"errorMessage":"no such service: %q: %w","messagePattern":"no such service: %q: %w","errorType":"validation","errorClass":"api.ErrNotFound","httpStatus":null,"severity":"error","filePath":"pkg/compose/compose.go","lineNumber":417,"sourceCode":"\t\t\t\t\tif len(dcArr) > 2 {\n\t\t\t\t\t\trestart, _ = strconv.ParseBool(dcArr[2])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tservice.DependsOn[dependency] = types.ServiceDependency{Condition: condition, Restart: restart, Required: required}\n\t\t\t}\n\t\t\tset[name] = service\n\t\t}\n\t}\n\tproject.Services = set\n\nSERVICES:\n\tfor _, qs := range services {\n\t\tfor _, es := range project.Services {\n\t\t\tif es.Name == qs {\n\t\t\t\tcontinue SERVICES\n\t\t\t}\n\t\t}\n\t\treturn project, fmt.Errorf(\"no such service: %q: %w\", qs, api.ErrNotFound)\n\t}\n\tproject, err := project.WithSelectedServices(services)\n\tif err != nil {\n\t\treturn project, err\n\t}\n\n\treturn project, nil\n}\n\nfunc increment(scale *int) *int {\n\ti := 1\n\tif scale != nil {\n\t\ti = *scale + 1\n\t}\n\treturn &i\n}\n\nfunc (s *composeService) actualVolumes(ctx context.Context, projectName string) (types.Volumes, error) {","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/compose.go#L399-L435","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\ndocker compose exec webs sh   # typo\n\n# after\ndocker compose exec web sh","handlingStrategy":"validation","validationCode":"existing := map[string]bool{}\nfor _, c := range containers { existing[c.Labels[api.ServiceLabel]] = true }\nfor _, name := range requestedServices {\n    if !existing[name] {\n        return fmt.Errorf(\"service %q has no containers in project\", name)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err != nil && errors.Is(err, api.ErrNotFound) {\n    // unknown service: verify spelling/profiles against `docker compose ps -a` before retrying\n}","preventionTips":["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"],"tags":["service","not-found","validation","runtime-state"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}