docker/cli · error

network name/id is not specified

Error message

network name/id is not specified

What it means

Returned by NetworkOpt.Set (opts/network.go:114) when the long syntax is detected (the value matches the key=value pattern) but no 'name=' field is provided, leaving the network Target empty. The long syntax requires at least a name (or network ID) to identify which network to attach to.

Solutions

  1. Add a 'name=<network-name-or-id>' field to the --network long syntax value.
  2. If you only want to specify a network by name without options, use short syntax: '--network mynet'.

Example fix

// before: long syntax without name
// docker run --network ip=1.2.3.4 nginx

// after: include name
// docker run --network name=mynet,ip=1.2.3.4 nginx
Defensive patterns

Strategy: validation

Validate before calling

func validateNetworkHasName(spec string) error {
    // Long syntax is detected by the regex in NetworkOpt.Set
    matched, _ := regexp.MatchString(`\w+=\w+(,\w+=\w+)*`, spec)
    if matched && !strings.Contains(strings.ToLower(spec), "name=") {
        return fmt.Errorf("long syntax --network requires a 'name=<network>' field")
    }
    return nil
}

Try / catch

if err := networkOpt.Set(value); err != nil {
    if err.Error() == "network name/id is not specified" {
        return fmt.Errorf("add 'name=<network-name-or-id>' to the --network spec")
    }
    return err
}

Prevention

When it happens

Trigger: A --network value is parsed as long syntax (contains key=value pairs) but none of the fields is 'name=...', so netOpt.Target remains empty after processing all fields. For example: '--network ip=1.2.3.4' or '--network alias=web'.

Common situations: Forgetting to include the 'name=' field when using long syntax, or assuming the network name can be inferred from other options.

Related errors


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

Appendix: source

Thrown at opts/network.go:114

				if netOpt.DriverOpts == nil {
					netOpt.DriverOpts = make(map[string]string)
				}
				netOpt.DriverOpts[key] = val
			case gwPriorityOpt:
				netOpt.GwPriority, err = strconv.Atoi(val)
				if err != nil {
					var numErr *strconv.NumError
					if errors.As(err, &numErr) {
						err = numErr.Err
					}
					return fmt.Errorf("invalid gw-priority (%s): %w", val, err)
				}
			default:
				return errors.New("invalid field key " + key)
			}
		}
		if len(netOpt.Target) == 0 {
			return errors.New("network name/id is not specified")
		}
	} else {
		netOpt.Target = value
	}
	n.options = append(n.options, netOpt)
	return nil
}

// Type returns the type of this option
func (*NetworkOpt) Type() string {
	return "network"
}

// Value returns the networkopts
func (n *NetworkOpt) Value() []NetworkAttachmentOpts {
	return n.options
}

View on GitHub (pinned to 4f84911bfe)