docker/cli · error
no name set for network
Error message
no name set for network
What it means
Thrown by parseNetworkAttachmentOpt when a network attachment entry has a blank Target after trimming whitespace. The Target field is the network name (or mode) the container attaches to; an empty value means the --network argument resolved to nothing parseable. This is a defensive guard before dereferencing the network mode downstream.
Solutions
- Verify the --network value is non-empty: echo it before running docker, or guard with a shell default `--network "${NET:?NET must be set}"`.
- Remove stray empty tokens from comma/space-separated network lists.
- If building NetworkAttachmentOpts in Go, set Target to a real network name before calling parseNetworkAttachmentOpt.
Example fix
// before NET="" docker run --network "$NET" alpine // after NET="mynet" docker run --network "$NET" alpine
Defensive patterns
Strategy: validation
Validate before calling
func validNetworkTarget(target string) error {
if strings.TrimSpace(target) == "" {
return errors.New("no name set for network")
}
return nil
}
// before invoking docker run / parseNetworkAttachmentOpt:
for _, n := range networks {
if err := validNetworkTarget(n); err != nil {
return err
}
} Prevention
- Always default --network to a concrete value: ${NET:-mynet} or ${NET:?required}.
- Strip empty tokens when splitting comma/space-separated network lists: filter `len(s)>0`.
- In Go code, assert Target is non-empty before constructing NetworkAttachmentOpts.
When it happens
Trigger: Passing `--network=` (empty value) or `--network " "` (whitespace). Also reachable via programmatic calls that build a NetworkAttachmentOpts with an empty Target, or a malformed comma/space separated --network list producing an empty element (e.g. `--network mynet,,other`).
Common situations: Shell variable expansion yielding an empty string: `docker run --network "$NET"` when NET is unset. Compose/network config templates with an unfilled placeholder. Scripts splitting on a delimiter producing empty tokens.
Related errors
- container name cannot be empty
- cannot attach to a stopped container, start it first
- cannot attach to a paused container, unpause it first
- cannot attach to a restarting container, wait until it is…
- source can not be empty
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/309f0924a4c5455e.
Report an issue: GitHub.
Appendix: source
Thrown at cli/command/container/opts.go:861
}
}
if copts.ipv6Address != nil {
if ipv6, ok := netip.AddrFromSlice(copts.ipv6Address.To16()); ok {
n.IPv6Address = ipv6
}
}
if copts.macAddress != "" {
n.MacAddress = copts.macAddress
}
if copts.linkLocalIPs.Len() > 0 {
n.LinkLocalIPs = toNetipAddrSlice(copts.linkLocalIPs.GetSlice())
}
return nil
}
func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.EndpointSettings, error) {
if strings.TrimSpace(ep.Target) == "" {
return nil, errors.New("no name set for network")
}
if !container.NetworkMode(ep.Target).IsUserDefined() {
if len(ep.Aliases) > 0 {
return nil, errors.New("network-scoped aliases are only supported for user-defined networks")
}
if len(ep.Links) > 0 {
return nil, errors.New("links are only supported for user-defined networks")
}
}
epConfig := &network.EndpointSettings{
GwPriority: ep.GwPriority,
}
epConfig.Aliases = append(epConfig.Aliases, ep.Aliases...)
if len(ep.DriverOpts) > 0 {
epConfig.DriverOpts = make(map[string]string)
epConfig.DriverOpts = ep.DriverOpts
}View on GitHub (pinned to 4f84911bfe)