{"id":"bd02e8586a5a2683","repo":"docker/cli","slug":"invalid-ip-address-in-add-host-q","errorCode":null,"errorMessage":"invalid IP address in add-host: %q","messagePattern":"invalid IP address in add-host: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/hosts.go","lineNumber":189,"sourceCode":"\t// '--add-host'. So, it'll split at the first colon and generate a strange error\n\t// message.)\n\tif !ok || k == \"\" || strings.Contains(k, \":\") {\n\t\treturn \"\", fmt.Errorf(\"bad format for add-host: %q\", val)\n\t}\n\t// Skip IPaddr validation for \"host-gateway\" string\n\tif v != hostGatewayName {\n\t\t// If the address is enclosed in square brackets, extract it (for IPv6, but\n\t\t// permit it for IPv4 as well; we don't know the address family here, but it's\n\t\t// unambiguous).\n\t\tif len(v) > 2 && v[0] == '[' && v[len(v)-1] == ']' {\n\t\t\tv = v[1 : len(v)-1]\n\t\t}\n\t\t// ValidateIPAddress returns the address in canonical form (for example,\n\t\t// 0:0:0:0:0:0:0:1 -> ::1). But, stick with the original form, to avoid\n\t\t// surprising a user who's expecting to see the address they supplied in the\n\t\t// output of 'docker inspect' or '/etc/hosts'.\n\t\tif _, err := ValidateIPAddress(v); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"invalid IP address in add-host: %q\", v)\n\t\t}\n\t}\n\t// This result is passed directly to the API, the daemon doesn't accept the '='\n\t// separator or an address enclosed in brackets. So, construct something it can\n\t// understand.\n\treturn k + \":\" + v, nil\n}\n","sourceCodeStart":171,"sourceCodeEnd":197,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/opts/hosts.go#L171-L197","documentation":"Error \"invalid IP address in add-host: %q\" thrown in docker/cli.","triggerScenarios":"Thrown at opts/hosts.go:189 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}