{"record":{"id":"042bc9b6e89ff855","repo":"juanfont/headscale","slug":"creating-docker-client-w","errorCode":null,"errorMessage":"creating Docker client: %w","messagePattern":"creating Docker client: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/hi/cleanup.go","lineNumber":60,"sourceCode":"\t\treturn fmt.Errorf(\"removing test container: %w\", err)\n\t}\n\n\t// Clean up integration test containers for this run only\n\tif runID != \"\" {\n\t\terr := killTestContainersByRunID(ctx, runID)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cleaning up containers for run %s: %w\", runID, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// killTestContainers terminates and removes all test containers.\nfunc killTestContainers(ctx context.Context) error {\n\tcli, err := createDockerClient(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating Docker client: %w\", err)\n\t}\n\tdefer cli.Close()\n\n\tcontainers, err := cli.ContainerList(ctx, container.ListOptions{\n\t\tAll: true,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"listing containers: %w\", err)\n\t}\n\n\tremoved := 0\n\n\tfor _, cont := range containers {\n\t\tif isTestContainerName(cont.Names) {\n\t\t\tif killAndRemove(ctx, cli, cont) {\n\t\t\t\tremoved++\n\t\t\t}\n\t\t}","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/cleanup.go#L42-L78","documentation":"Returned by killTestContainers when createDockerClient fails. createDockerClient negotiates a Docker client from the environment (DOCKER_HOST, DOCKER_CONTEXT, or the default unix socket), so this error means no usable daemon connection could be established: missing socket, unreachable remote host, or an invalid DOCKER_HOST URL.","triggerScenarios":"Running `hi kill` (or any path into killTestContainers) with the Docker daemon stopped, DOCKER_HOST set to a dead URL (e.g. tcp://127.0.0.1:2375 with nothing listening), a nonexistent docker context, or without read permission on /var/run/docker.sock.","commonSituations":"Fresh machines where the user is not in the docker group; DOCKER_HOST exported for a remote daemon that is since gone; Docker Desktop not started; rootless daemon socket path not set; CI runners where the docker socket is mounted at a nonstandard path.","solutions":["Run `docker version` as the same user to confirm daemon connectivity","Start the daemon (systemctl start docker / open Docker Desktop)","Fix or unset DOCKER_HOST and DOCKER_CONTEXT; run `docker context ls` to pick a valid one","sudo usermod -aG docker $USER then log out/in for socket permission","For nonstandard sockets: export DOCKER_HOST=unix:///path/to/docker.sock"],"exampleFix":"# before\nDOCKER_HOST=tcp://127.0.0.1:2375 go run ./cmd/hi kill\n# error: creating Docker client: ...\n\n# after (use local daemon)\nunset DOCKER_HOST\ngo run ./cmd/hi kill","handlingStrategy":"validation","validationCode":"// Fail fast with a clear message if Docker is unusable.\nfunc requireDocker(ctx context.Context) error {\n\tcli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"docker client: %w\", err)\n\t}\n\tdefer cli.Close()\n\tif _, err := cli.Ping(ctx); err != nil {\n\t\treturn fmt.Errorf(\"docker daemon unreachable: %w\", err)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"Distinguish client-creation errors (config/env problem — fix environment) from API errors (daemon problem — restart/retry) by inspecting the wrapped error.","preventionTips":["Start each session with `docker version`","Set DOCKER_HOST explicitly in scripts rather than relying on inherited shell state","Use `docker context use <name>` to make context selection persistent and valid","Run `hi doctor` first on new machines"],"tags":["docker","client-init","environment","hi"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}