docker/cli · error

duplicate mount target

Error message

duplicate mount target

What it means

Emitted by `docker service update --mount-add`. updateMounts (update.go:927-937) indexes the newly added mounts by their Target path; if two --mount-add flags in the same command declare the same target, the second insert hits the map and the CLI errors, because two mounts cannot occupy one container path. (Adding a mount whose target matches an existing service mount is fine — it replaces it.)

Source

Thrown at cli/command/service/update.go:934

	keyFunc func(string) string,
) []string {
	newSeq := []string{}
	for _, item := range seq {
		if _, exists := toRemove[keyFunc(item)]; !exists {
			newSeq = append(newSeq, item)
		}
	}
	return newSeq
}

func updateMounts(flags *pflag.FlagSet, mounts *[]mount.Mount) error {
	mountsByTarget := map[string]mount.Mount{}

	if flags.Changed(flagMountAdd) {
		values := flags.Lookup(flagMountAdd).Value.(*opts.MountOpt).Value()
		for _, mnt := range values {
			if _, ok := mountsByTarget[mnt.Target]; ok {
				return errors.New("duplicate mount target")
			}
			mountsByTarget[mnt.Target] = mnt
		}
	}

	// Add old list of mount points minus updated one.
	for _, mnt := range *mounts {
		if _, ok := mountsByTarget[mnt.Target]; !ok {
			mountsByTarget[mnt.Target] = mnt
		}
	}

	newMounts := make([]mount.Mount, 0, len(mountsByTarget))

	toRemove := buildToRemoveSet(flags, flagMountRemove)

	for _, mnt := range mountsByTarget {
		if _, exists := toRemove[mnt.Target]; !exists {

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Remove or change one of the duplicate `target=` paths so each --mount-add has a unique container path
  2. If the intent is to replace an existing mount, pass a single --mount-add with that target (it supersedes the old one) — no --mount-rm needed
  3. Deduplicate the mount list in the script that generates the command

Example fix

# before
docker service update \
  --mount-add type=volume,source=a,target=/data \
  --mount-add type=volume,source=b,target=/data web

# after
docker service update \
  --mount-add type=volume,source=a,target=/data \
  --mount-add type=volume,source=b,target=/data-b web

When it happens

Trigger: `docker service update --mount-add target=/data,source=v1 --mount-add target=/data,source=v2 svc` — two mount-add values with identical `target=` in one invocation.

Common situations: Templated/generated update commands that concatenate mount lists with duplicates; copy-paste of a --mount-add flag without changing the target; scripts merging default and override mounts that both map the same path.

Related errors


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/02ce7b85b0ecd720.json. Report an issue: GitHub.