docker/cli · error

invalid tmpfs source, source must be empty

Error message

invalid tmpfs source, source must be empty

What it means

Returned by handleTmpfsToMount (cli/compose/convert/volume.go:149-150). Unlike every other type, tmpfs is an anonymous in-memory filesystem and must NOT declare a source path. The guard is the inverse of the bind/npipe/cluster checks: a non-empty source is the error condition.

Solutions

  1. Remove the `source:` key from the tmpfs entry (only `target` is needed).
  2. If you need a size cap, keep it under `tmpfs: { size: <bytes> }` and leave source empty.
  3. If you actually wanted to mount a host path or named volume, pick `type: bind` or `type: volume` instead.

Example fix

# before
volumes:
  - type: tmpfs
    source: /tmp/cache
    target: /cache
    tmpfs:
      size: 67108864

# after
volumes:
  - type: tmpfs
    target: /cache
    tmpfs:
      size: 67108864
Defensive patterns

Strategy: validation

Validate before calling

for i, v := range serviceVolumes {
    if v.Type == "tmpfs" && strings.TrimSpace(v.Source) != "" {
        return fmt.Errorf("service volume[%d] target=%q: type tmpfs must have an empty source (it is in-memory)", i, v.Target)
    }
}

Try / catch

mounts, err := convert.Volumes(serviceVolumes, stackVolumes, namespace)
if err != nil && strings.Contains(err.Error(), "invalid tmpfs source") {
    return fmt.Errorf("compose config error: %w (delete the source: line from the tmpfs entry)", err)
}

Prevention

When it happens

Trigger: ServiceVolumeConfig with Type=="tmpfs" and Source!="" passed to convertVolumeToMount().

Common situations: Adding `type: tmpfs` to a pre-existing volume entry that still has `source:` set; assuming tmpfs needs a source like the other types; converting a bind to tmpfs and forgetting to delete the source line.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/632e5b231ea5406b. Report an issue: GitHub.

Appendix: source

Thrown at cli/compose/convert/volume.go:150

	if volume.Tmpfs != nil {
		return mount.Mount{}, errors.New("tmpfs options are incompatible with type bind")
	}
	if volume.Cluster != nil {
		return mount.Mount{}, errors.New("cluster options are incompatible with type bind")
	}
	if volume.Bind != nil {
		result.BindOptions = &mount.BindOptions{
			Propagation: mount.Propagation(volume.Bind.Propagation),
		}
	}
	return result, nil
}

func handleTmpfsToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, error) {
	result := createMountFromVolume(volume)

	if volume.Source != "" {
		return mount.Mount{}, errors.New("invalid tmpfs source, source must be empty")
	}
	if volume.Bind != nil {
		return mount.Mount{}, errors.New("bind options are incompatible with type tmpfs")
	}
	if volume.Volume != nil {
		return mount.Mount{}, errors.New("volume options are incompatible with type tmpfs")
	}
	if volume.Image != nil {
		return mount.Mount{}, errors.New("image options are incompatible with type tmpfs")
	}
	if volume.Cluster != nil {
		return mount.Mount{}, errors.New("cluster options are incompatible with type tmpfs")
	}
	if volume.Tmpfs != nil {
		result.TmpfsOptions = &mount.TmpfsOptions{
			SizeBytes: volume.Tmpfs.Size,
		}
	}

View on GitHub (pinned to 4f84911bfe)