docker/compose · error

cannot share PID namespace with service %s: container missin

Error message

cannot share PID namespace with service %s: container missing

What it means

The PID arm of resolveSharedNamespaces: `pid: "service:<name>"` needs a live container of that service to rewrite the reference into container:<id>. An empty containersByService entry for the named dependency makes the PID namespace unshareable and stops convergence with this error.

Source

Thrown at pkg/compose/convergence.go:113

		dependencies := containersByService[name]
		if len(dependencies) == 0 {
			return fmt.Errorf("cannot share network namespace with service %s: container missing", name)
		}
		service.NetworkMode = types.ContainerPrefix + dependencies.sorted()[0].ID
	}

	if name := getDependentServiceFromMode(service.Ipc); name != "" {
		dependencies := containersByService[name]
		if len(dependencies) == 0 {
			return fmt.Errorf("cannot share IPC namespace with service %s: container missing", name)
		}
		service.Ipc = types.ContainerPrefix + dependencies.sorted()[0].ID
	}

	if name := getDependentServiceFromMode(service.Pid); name != "" {
		dependencies := containersByService[name]
		if len(dependencies) == 0 {
			return fmt.Errorf("cannot share PID namespace with service %s: container missing", name)
		}
		service.Pid = types.ContainerPrefix + dependencies.sorted()[0].ID
	}

	return nil
}

func getContainerName(projectName string, service types.ServiceConfig, number int) string {
	name := getDefaultContainerName(projectName, service.Name, strconv.Itoa(number))
	if service.ContainerName != "" {
		name = service.ContainerName
	}
	return name
}

func getDefaultContainerName(projectName, serviceName, index string) string {
	return strings.Join([]string{projectName, serviceName, index}, api.Separator)
}

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Start both services together or add `depends_on` so the PID provider exists first
  2. Inspect why the provider is absent: `docker compose ps -a <provider>`, `docker compose logs <provider>`
  3. If you only need a PID namespace without a specific peer, use `pid: host` or a pod-like single-container design instead

Example fix

# before
services:
  supervisor:
    image: busybox
  app:
    pid: "service:supervisor"

# after
services:
  supervisor:
    image: busybox
  app:
    depends_on: [supervisor]
    pid: "service:supervisor"
Defensive patterns

Strategy: validation

Validate before calling

if name := getDependentServiceFromMode(svc.Pid); name != "" {
    if len(containersByService[name]) == 0 {
        return fmt.Errorf("pid service:%s has no containers", name)
    }
}

Prevention

When it happens

Trigger: `docker compose up` with `pid: service:sidecar` where the sidecar service has no containers — not created in this run, removed, or crashed before the dependent converged.

Common situations: Monitoring/signal-forwarding designs (share PID with an init or supervisor sidecar); starting the dependent alone with `docker compose up app`; sidecar OOM-killed at startup so its container vanishes.

Related errors


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