{"record":{"id":"0ca2701d838419cb","repo":"docker/compose","slug":"cannot-share-network-namespace-with-service-s-co","errorCode":null,"errorMessage":"cannot share network namespace with service %s: container missing","messagePattern":"cannot share network namespace with service (.+?): container missing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compose/convergence.go","lineNumber":97,"sourceCode":"\t\tif spec[0] == \"container\" {\n\t\t\tservice.VolumesFrom[i] = spec[1]\n\t\t\tcontinue\n\t\t}\n\t\tname := spec[0]\n\t\tdependencies := containersByService[name]\n\t\tif len(dependencies) == 0 {\n\t\t\treturn fmt.Errorf(\"cannot share volume with service %s: container missing\", name)\n\t\t}\n\t\tservice.VolumesFrom[i] = dependencies.sorted()[0].ID\n\t}\n\treturn nil\n}\n\nfunc resolveSharedNamespaces(service *types.ServiceConfig, containersByService map[string]Containers) error {\n\tif name := getDependentServiceFromMode(service.NetworkMode); name != \"\" {\n\t\tdependencies := containersByService[name]\n\t\tif len(dependencies) == 0 {\n\t\t\treturn fmt.Errorf(\"cannot share network namespace with service %s: container missing\", name)\n\t\t}\n\t\tservice.NetworkMode = types.ContainerPrefix + dependencies.sorted()[0].ID\n\t}\n\n\tif name := getDependentServiceFromMode(service.Ipc); name != \"\" {\n\t\tdependencies := containersByService[name]\n\t\tif len(dependencies) == 0 {\n\t\t\treturn fmt.Errorf(\"cannot share IPC namespace with service %s: container missing\", name)\n\t\t}\n\t\tservice.Ipc = types.ContainerPrefix + dependencies.sorted()[0].ID\n\t}\n\n\tif name := getDependentServiceFromMode(service.Pid); name != \"\" {\n\t\tdependencies := containersByService[name]\n\t\tif len(dependencies) == 0 {\n\t\t\treturn fmt.Errorf(\"cannot share PID namespace with service %s: container missing\", name)\n\t\t}\n\t\tservice.Pid = types.ContainerPrefix + dependencies.sorted()[0].ID","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/pkg/compose/convergence.go#L79-L115","documentation":"resolveSharedNamespaces handles network_mode values of the form 'service:<name>': it must replace the service reference with the actual container ID (container:<id>) before container creation. If the referenced service has no containers in containersByService, the mode cannot be resolved and the error is returned.","triggerScenarios":"`docker compose up` with `network_mode: \"service:vpn\"` where the vpn service has no containers — not started, crashed, or excluded from the current selection (e.g. started with an explicit service list that omits it).","commonSituations":"Sidecar-pattern files (share network with a VPN/proxy container) where the sidecar fails to pull or exits instantly; starting only the dependent service (`docker compose up app`) without its namespace provider; profile-gated providers not activated.","solutions":["Start the provider service too: `docker compose up -d vpn app` (or add depends_on: [vpn])","Diagnose why the provider has no container: `docker compose ps -a vpn`, check image pull and crash logs","Ensure the provider isn't behind an inactive profile, or activate the profile with `--profile`"],"exampleFix":"# before\nservices:\n  vpn:\n    profile: [net]\n  app:\n    network_mode: \"service:vpn\"\n\n# after (activate profile / depends_on)\n# docker compose --profile net up -d\nservices:\n  vpn:\n    profile: [net]\n  app:\n    depends_on: [vpn]\n    network_mode: \"service:vpn\"","handlingStrategy":"validation","validationCode":"if name := getDependentServiceFromMode(svc.NetworkMode); name != \"\" {\n    if len(containersByService[name]) == 0 {\n        return fmt.Errorf(\"network_mode service:%s has no containers\", name)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always start namespace-provider services together with dependents (depends_on or explicit up list)","Keep providers out of inactive profiles when dependents reference them via service: modes"],"tags":["network-mode","namespaces","dependencies","convergence"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}