{"record":{"id":"d1ee38d58ea994a2","repo":"docker/cli","slug":"w-specify-one-with-advertise-addr","errorCode":null,"errorMessage":"%w - specify one with --advertise-addr","messagePattern":"%w - specify one with --advertise-addr","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/swarm/init.go","lineNumber":113,"sourceCode":"\t\t\treturn fmt.Errorf(\"invalid availability %q, only active, pause and drain are supported\", opts.availability)\n\t\t}\n\t}\n\n\tres, err := apiClient.SwarmInit(ctx, client.SwarmInitOptions{\n\t\tListenAddr:       opts.listenAddr.String(),\n\t\tAdvertiseAddr:    opts.advertiseAddr,\n\t\tDataPathAddr:     opts.dataPathAddr,\n\t\tDataPathPort:     opts.dataPathPort,\n\t\tDefaultAddrPool:  defaultAddrPool,\n\t\tForceNewCluster:  opts.forceNewCluster,\n\t\tSpec:             opts.swarmOptions.ToSpec(flags),\n\t\tAutoLockManagers: opts.swarmOptions.autolock,\n\t\tAvailability:     availability,\n\t\tSubnetSize:       opts.DefaultAddrPoolMaskLength,\n\t})\n\tif err != nil {\n\t\tif strings.Contains(err.Error(), \"could not choose an IP address to advertise\") || strings.Contains(err.Error(), \"could not find the system's IP address\") {\n\t\t\treturn fmt.Errorf(\"%w - specify one with --advertise-addr\", err)\n\t\t}\n\t\treturn err\n\t}\n\n\t_, _ = fmt.Fprintf(dockerCLI.Out(), \"Swarm initialized: current node (%s) is now a manager.\\n\\n\", res.NodeID)\n\n\tif err := printJoinCommand(ctx, dockerCLI, res.NodeID, true, false); err != nil {\n\t\treturn err\n\t}\n\n\t_, _ = fmt.Fprintln(dockerCLI.Out(), \"To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.\")\n\n\tif opts.swarmOptions.autolock {\n\t\tresp, err := apiClient.SwarmGetUnlockKey(ctx)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not fetch unlock key: %w\", err)\n\t\t}\n\t\tprintUnlockCommand(dockerCLI.Out(), resp.Key)","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/swarm/init.go#L95-L131","documentation":"Wraps a daemon error from SwarmInit when the manager could not determine an IP address to advertise. The CLI detects the phrases 'could not choose an IP address to advertise' / 'could not find the system's IP address' and appends guidance to set --advertise-addr.","triggerScenarios":"'docker swarm init' on a host whose network interfaces are all down, loopback-only, ambiguous (multiple IPs with no clear choice), or in a restricted container without host networking. The daemon returns an advertise-selection error which the CLI re-wraps.","commonSituations":"Init in a container without host network mode; multi-homed hosts; air-gapped VMs with only lo; CI runners with no routable interface.","solutions":["Provide an explicit advertise address: 'docker swarm init --advertise-addr <ip|iface>'.","Ensure at least one non-loopback interface is up with an IP ('ip addr').","In containers, run with appropriate network visibility (--net=host or a known interface)."],"exampleFix":"# before\ndocker swarm init\n\n# after\ndocker swarm init --advertise-addr 10.0.0.5\n# -or-\ndocker swarm init --advertise-addr eth0","handlingStrategy":"fallback","validationCode":"// Probe interfaces and supply --advertise-addr proactively\nif addr, err := pickFirstGlobalIPv4(); err == nil {\n    args = append(args, \"--advertise-addr\", addr)\n}","typeGuard":"func hasAdvertiseAddr(flags *pflag.FlagSet) bool {\n\treturn flags.Changed(flagAdvertiseAddr)\n}","tryCatchPattern":"if err := runInit(ctx, cli, flags, opts); err != nil {\n    if strings.Contains(err.Error(), \"specify one with --advertise-addr\") {\n        // retry with a discovered interface address\n        flags.Set(flagAdvertiseAddr, discoveredAddr)\n        return runInit(ctx, cli, flags, opts)\n    }\n    return err\n}","preventionTips":["Always pass --advertise-addr in automation.","Ensure a routable interface is up before init.","In containers, use host networking or an explicit interface."],"tags":["swarm","init","network","advertise-addr"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}