{"record":{"id":"e21bcad4f2b1a55d","repo":"abiosoft/colima","slug":"container-ip-is-empty","errorCode":null,"errorMessage":"container IP is empty","messagePattern":"container IP is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"model/docker.go","lineNumber":291,"sourceCode":"\t\tlog.Infof(\"docker-model-runner not found, starting it (attempt %d/3)...\", attempt)\n\t\t_ = guest.Run(\"docker\", \"model\", \"start-runner\")\n\t\ttime.Sleep(2 * time.Second)\n\t}\n\n\treturn fmt.Errorf(\"could not start docker-model-runner after 3 attempts\")\n}\n\n// getDockerModelRunnerIP returns the IP address of the docker-model-runner container.\nfunc getDockerModelRunnerIP(guest environment.VM) (string, error) {\n\toutput, err := guest.RunOutput(\"docker\", \"inspect\", \"docker-model-runner\",\n\t\t\"--format\", \"{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get container IP: %w\", err)\n\t}\n\n\tip := strings.TrimSpace(output)\n\tif ip == \"\" {\n\t\treturn \"\", fmt.Errorf(\"container IP is empty\")\n\t}\n\n\treturn ip, nil\n}\n\n// startSocat starts socat in the background to forward a port to the container.\nfunc startSocat(guest environment.VM, port int, containerIP string) error {\n\tcmd := fmt.Sprintf(\"nohup socat TCP-LISTEN:%d,fork,reuseaddr TCP:%s:%d > /dev/null 2>&1 &\",\n\t\tport, containerIP, port)\n\treturn guest.Run(\"sh\", \"-c\", cmd)\n}\n\n// stopSocat stops the socat process for a given port.\nfunc stopSocat(guest environment.VM, port int) {\n\tcmd := fmt.Sprintf(\"pkill -f 'socat.*TCP-LISTEN:%d' 2>/dev/null || true\", port)\n\t_ = guest.Run(\"sh\", \"-c\", cmd)\n}\n","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/model/docker.go#L273-L309","documentation":"getDockerModelRunnerIP succeeded at the docker inspect level but the templated output trimmed to an empty string: the container is attached to no network, or to networks that report no IPAddress. This happens when the container is created but not running, uses host networking, or was inspected before its network attachment completed.","triggerScenarios":"docker-model-runner in Created/Exited state (inspect works, NetworkSettings empty); runner using host network mode with no bridge IP; inspect racing container start so the IP is not yet assigned.","commonSituations":"Runner container stopped after ensureDockerModelRunner's coarse check; newer runner images switching network modes; freshly started containers on slow VMs.","solutions":["Confirm it is actually running: colima ssh -- docker ps | grep docker-model-runner (not just inspect-able)","Restart the runner (docker model start-runner) and retry serve","Inspect its networks manually: docker inspect docker-model-runner --format '{{json .NetworkSettings.Networks}}'","If the runner legitimately has no IP (host networking), colima's socat forwarding needs a code fix — report/update colima"],"exampleFix":"// before: single shot\noutput, _ := guest.RunOutput(\"docker\", \"inspect\", \"docker-model-runner\", \"--format\", tpl)\nip := strings.TrimSpace(output)\n\n// after: brief retry while the container gets an IP\nvar ip string\nfor i := 0; i < 5; i++ {\n    output, _ := guest.RunOutput(\"docker\", \"inspect\", \"docker-model-runner\", \"--format\", tpl)\n    if ip = strings.TrimSpace(output); ip != \"\" {\n        break\n    }\n    time.Sleep(time.Second)\n}","handlingStrategy":"retry","validationCode":"// Require Running state (not just existence) before reading the IP.\nfunc runnerReady(guest environment.VM) bool {\n    out, err := guest.RunOutput(\"docker\", \"inspect\", \"-f\",\n        \"{{.State.Running}} {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}\",\n        \"docker-model-runner\")\n    return err == nil && strings.HasPrefix(strings.TrimSpace(out), \"true \")\n}","typeGuard":null,"tryCatchPattern":"ip := strings.TrimSpace(output)\nfor i := 0; ip == \"\" && i < 5; i++ {\n    time.Sleep(time.Second) // container may still be attaching to its network\n    output, err = guest.RunOutput(\"docker\", \"inspect\", \"docker-model-runner\", \"--format\", tpl)\n    if err != nil { break }\n    ip = strings.TrimSpace(output)\n}\nif ip == \"\" { return \"\", fmt.Errorf(\"container IP is empty\") }","preventionTips":["Check State.Running, not just container existence, before reading network settings","Give freshly started runner containers a short grace period before querying their IP","If the runner uses host networking (no IP by design), update colima's forwarding approach rather than retrying"],"tags":["docker","networking","container-ip","model-runner"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}