{"record":{"id":"49f9b3c6c37c5aac","repo":"docker/compose","slug":"no-container-found-for-project-q-w","errorCode":null,"errorMessage":"no container found for project %q: %w","messagePattern":"no container found for project %q: %w","errorType":"exception","errorClass":"api.ErrNotFound","httpStatus":null,"severity":"error","filePath":"pkg/compose/compose.go","lineNumber":365,"sourceCode":"func getContainerNameWithoutProject(c container.Summary) string {\n\tproject := c.Labels[api.ProjectLabel]\n\tdefaultName := getDefaultContainerName(project, c.Labels[api.ServiceLabel], c.Labels[api.ContainerNumberLabel])\n\tname := getCanonicalContainerName(c)\n\tif name != defaultName {\n\t\t// service declares a custom container_name\n\t\treturn name\n\t}\n\treturn name[len(project)+1:]\n}\n\n// projectFromName builds a types.Project based on actual resources with compose labels set\nfunc (s *composeService) projectFromName(containers Containers, projectName string, services ...string) (*types.Project, error) {\n\tproject := &types.Project{\n\t\tName:     projectName,\n\t\tServices: types.Services{},\n\t}\n\tif len(containers) == 0 {\n\t\treturn project, fmt.Errorf(\"no container found for project %q: %w\", projectName, api.ErrNotFound)\n\t}\n\tset := types.Services{}\n\tfor _, c := range containers {\n\t\tserviceLabel, ok := c.Labels[api.ServiceLabel]\n\t\tif !ok {\n\t\t\tserviceLabel = getCanonicalContainerName(c)\n\t\t}\n\t\tservice, ok := set[serviceLabel]\n\t\tif !ok {\n\t\t\tservice = types.ServiceConfig{\n\t\t\t\tName:   serviceLabel,\n\t\t\t\tImage:  c.Image,\n\t\t\t\tLabels: c.Labels,\n\t\t\t}\n\t\t}\n\t\tservice.Scale = increment(service.Scale)\n\t\tset[serviceLabel] = service\n\t}","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/compose.go#L347-L383","documentation":"projectFromName reconstructs a types.Project from actually existing Docker resources labeled for the project. When the container list passed in is empty it cannot build any service set, so it returns the project together with an error wrapping api.ErrNotFound. This powers commands that operate on existing state (e.g. images, ps-based flows) rather than the Compose file.","triggerScenarios":"Invoking compose API functions that derive the project from runtime state (projectFromName) when no containers carrying the project label exist — e.g. `docker compose images`/`restart`/`exec` before `up`, after `down`, or against a mistyped project name (`-p`).","commonSituations":"Running lifecycle commands in a fresh checkout without `up` first; scripts chaining `up -d && exec` where up failed silently; wrong project name because COMPOSE_PROJECT_NAME differs from the directory; containers removed by `down` or pruned.","solutions":["Start the project first: `docker compose up -d`, then re-run the failing command","Verify the project name matches what's running: `docker compose ls` and `docker ps --filter label=com.docker.compose.project","If containers were removed unexpectedly, check `docker compose ps -a` and `docker events` for prune/down activity"],"exampleFix":"# before\ndocker compose exec web sh        # no containers yet\n\n# after\ndocker compose up -d\ndocker compose exec web sh","handlingStrategy":"validation","validationCode":"containers, err := composeAPI.ListContainers(ctx, projectName, nil) // equivalent listing call\nif err == nil && len(containers) == 0 {\n    return fmt.Errorf(\"project %q has no containers; run up first\", projectName)\n}","typeGuard":null,"tryCatchPattern":"if err := op(ctx, project, ...); err != nil && errors.Is(err, api.ErrNotFound) {\n    // treat as 'not started yet': run up -d, then retry once\n}","preventionTips":["Gate runtime-state commands behind a successful `up -d` in scripts","Echo `docker compose ps` output when automation fails so state is visible"],"tags":["project","not-found","containers","runtime-state"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}