{"record":{"id":"bcac82dfc030e9cb","repo":"docker/compose","slug":"cannot-attach-to-services-not-included-in-up-s","errorCode":null,"errorMessage":"cannot attach to services not included in up: %s","messagePattern":"cannot attach to services not included in up: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/up.go","lineNumber":310,"sourceCode":"\t\treturn err\n\t}\n\n\tif upOptions.noStart {\n\t\treturn backend.Create(ctx, project, create)\n\t}\n\n\tvar consumer api.LogConsumer\n\tvar attach []string\n\tif !upOptions.Detach {\n\t\tconsumer = formatter.NewLogConsumer(ctx, dockerCli.Out(), dockerCli.Err(), !upOptions.noColor, !upOptions.noPrefix, upOptions.timestamp)\n\n\t\tvar attachSet utils.Set[string]\n\t\tif len(upOptions.attach) != 0 {\n\t\t\t// services are passed explicitly with --attach, verify they're valid and then use them as-is\n\t\t\tattachSet = utils.NewSet(upOptions.attach...)\n\t\t\tunexpectedSvcs := attachSet.Diff(utils.NewSet(project.ServiceNames()...))\n\t\t\tif len(unexpectedSvcs) != 0 {\n\t\t\t\treturn fmt.Errorf(\"cannot attach to services not included in up: %s\", strings.Join(unexpectedSvcs.Elements(), \", \"))\n\t\t\t}\n\t\t} else {\n\t\t\t// mark services being launched (and potentially their deps) for attach\n\t\t\t// if they didn't opt-out via Compose YAML\n\t\t\tattachSet = utils.NewSet[string]()\n\t\t\tvar dependencyOpt types.DependencyOption = types.IgnoreDependencies\n\t\t\tif upOptions.attachDependencies {\n\t\t\t\tdependencyOpt = types.IncludeDependencies\n\t\t\t}\n\t\t\tif err := project.ForEachService(services, func(serviceName string, s *types.ServiceConfig) error {\n\t\t\t\tif s.Attach == nil || *s.Attach {\n\t\t\t\t\tattachSet.Add(serviceName)\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t}, dependencyOpt); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/up.go#L292-L328","documentation":"Returned during runUp (foreground up) when the user explicitly passed --attach SERVICE and some of those services are not part of the project being started. The code builds a set from upOptions.attach and diffs it against project.ServiceNames(); any name not present in the project produces this error listing the unexpected services. It guards against silently waiting on containers that will never be launched.","triggerScenarios":"`docker compose up --attach sidecar web` where 'sidecar' is not defined in compose.yml; attaching to a service filtered out by profiles (service exists in file but inactive in the resolved project); typos in the service name; attaching to a service that only exists in a different COMPOSE_FILE overlay not loaded this run.","commonSituations":"Multi-service repos where the attach list was written for the full stack but up runs a subset (services arg or profile filtering); renamed services leaving stale attach lists in scripts; typos.","solutions":["Remove or fix the listed service names in --attach so all are in `docker compose config --services` output for this exact invocation.","If the service is profile-gated, enable its profile (--profile X or COMPOSE_PROFILES).","Check overlays: ensure the COMPOSE_FILE set that defines the service is loaded."],"exampleFix":"# before\n# 'sidecar' not defined in compose.yml\ndocker compose up --attach sidecar web\n\n# after\ndocker compose up --attach web","handlingStrategy":"validation","validationCode":"# validate --attach names against this run's resolved services\nmapfile -t valid < <(docker compose config --services)\nfor a in \"${ATTACH[@]}\"; do\n  printf '%s\\n' \"${valid[@]}\" | grep -qx \"$a\" || { echo \"unknown attach target: $a\" >&2; exit 2; }\ndone\ndocker compose up --attach \"${ATTACH[@]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate --attach lists from `docker compose config --services` output.","Re-check attach lists after renaming services or changing profiles.","Remember profiles filter the project before the attach diff runs."],"tags":["cli","up","attach","services","validation","compose"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}