docker/compose · error

cannot share volume with service %s: container missing

Error message

cannot share volume with service %s: container missing

What it means

resolveVolumeFrom rewrites each volumes_from entry that references a service name into a container ID. It looks the dependency up in containersByService; if the referenced service has zero containers, there is nothing to share volumes from, so convergence aborts with this error. Entries of the form 'container:<id>' pass through untouched.

Source

Thrown at pkg/compose/convergence.go:86

		return err
	}
	return resolveSharedNamespaces(service, containersByService)
}

func resolveVolumeFrom(service *types.ServiceConfig, containersByService map[string]Containers) error {
	for i, vol := range service.VolumesFrom {
		spec := strings.Split(vol, ":")
		if len(spec) == 0 {
			continue
		}
		if spec[0] == "container" {
			service.VolumesFrom[i] = spec[1]
			continue
		}
		name := spec[0]
		dependencies := containersByService[name]
		if len(dependencies) == 0 {
			return fmt.Errorf("cannot share volume with service %s: container missing", name)
		}
		service.VolumesFrom[i] = dependencies.sorted()[0].ID
	}
	return nil
}

func resolveSharedNamespaces(service *types.ServiceConfig, containersByService map[string]Containers) error {
	if name := getDependentServiceFromMode(service.NetworkMode); name != "" {
		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 {

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Add `depends_on` for the shared-from service so it is created first, and confirm it starts successfully
  2. Check the dependency actually exists: `docker compose ps <dep>`; fix crashes or name typos
  3. If sharing data rather than a container is the goal, switch to a named volume mounted by both services

Example fix

# before
services:
  data:
    image: busybox
  app:
    volumes_from:
      - data   # may not exist yet

# after
services:
  data:
    image: busybox
  app:
    depends_on:
      - data
    volumes_from:
      - data
Defensive patterns

Strategy: validation

Validate before calling

for _, vf := range svc.VolumesFrom {
    name := strings.SplitN(vf, ":", 2)[0]
    if name == "container" { continue }
    if len(containersByService[name]) == 0 {
        return fmt.Errorf("volumes_from target %s has no containers", name)
    }
}

Prevention

When it happens

Trigger: `docker compose up` where a service declares `volumes_from: [otherservice]` but otherservice has no running/created containers — dependency failed to create, was removed mid-run, or is listed without being part of this project's started set.

Common situations: Missing depends_on so the dependency isn't created yet when the dependent converges; dependency crashed immediately and its container was cleaned up (--rm one-off behavior); typo in the volumes_from service name.

Related errors


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