{"record":{"id":"7982bb283932f234","repo":"juanfont/headscale","slug":"getting-docker-context-w","errorCode":null,"errorMessage":"getting docker context: %w","messagePattern":"getting docker context: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/hi/docker.go","lineNumber":490,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif len(clientOpts) == 1 {\n\t\tclientOpts = append(clientOpts, client.FromEnv)\n\t}\n\n\treturn client.NewClientWithOpts(clientOpts...)\n}\n\n// getCurrentDockerContext retrieves the current Docker context information.\nfunc getCurrentDockerContext(ctx context.Context) (*DockerContext, error) {\n\tcmd := exec.CommandContext(ctx, \"docker\", \"context\", \"inspect\")\n\n\toutput, err := cmd.Output()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting docker context: %w\", err)\n\t}\n\n\tvar contexts []DockerContext\n\tif err := json.Unmarshal(output, &contexts); err != nil { //nolint:noinlineerr\n\t\treturn nil, fmt.Errorf(\"parsing docker context: %w\", err)\n\t}\n\n\tif len(contexts) > 0 {\n\t\treturn &contexts[0], nil\n\t}\n\n\treturn nil, ErrNoDockerContext\n}\n\n// getDockerSocketPath returns the correct Docker socket path for the current context.\nfunc getDockerSocketPath() string {\n\t// Always use the default socket path for mounting since Docker handles\n\t// the translation to the actual socket (e.g., colima socket) internally","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/docker.go#L472-L508","documentation":"Returned by `getCurrentDockerContext` when shelling out to `docker context inspect` fails — the docker CLI is missing from PATH, exited non-zero (no CLI config, invalid current context), or the context deadline hit. This runs to decide client options (e.g. custom host) and socket path handling for the test runner.","triggerScenarios":"The `docker` binary is not installed or not on PATH when running `hi`; DOCKER_CONFIG points at a broken config dir; the current context is set to a deleted context; the passed ctx is cancelled.","commonSituations":"Running `hi` in an environment with only the Docker SDK and no CLI; CI images that install docker CLI late; switching to colima then removing its context; DOCKER_CONFIG env var pointing to a missing directory.","solutions":["Ensure `docker` CLI is installed: `which docker && docker context ls`.","Fix or recreate the current context: `docker context create ...` or `docker context use default`.","Check DOCKER_CONFIG points to a valid directory with readable config.json.","Verify the default docker socket exists when using the default context."],"exampleFix":"# before: broken current context\ndocker context use deleted-ctx\ngo run ./cmd/hi run TestX   # -> getting docker context: ...\n\n# after: point at a valid context\ndocker context use default\ngo run ./cmd/hi run TestX","handlingStrategy":"validation","validationCode":"// verify docker CLI and context before invoking hi\nif err := exec.Command(\"docker\", \"context\", \"ls\").Run(); err != nil {\n    return fmt.Errorf(\"docker CLI/context unusable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := runDockerTest(ctx, config); err != nil {\n    if strings.Contains(err.Error(), \"getting docker context\") {\n        // fix CLI install or `docker context use default`, then retry\n    }\n}","preventionTips":["Install the docker CLI wherever hi runs.","Pin a known-good docker context in CI setup.","Validate DOCKER_CONFIG points to an existing directory."],"tags":["docker","docker-context","cli","environment","hi-runner"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}