{"record":{"id":"7bd373fd11bc15a8","repo":"hashicorp/nomad","slug":"failed-to-get-docker-client-w","errorCode":null,"errorMessage":"failed to get docker client: %w","messagePattern":"failed to get docker client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/driver.go","lineNumber":255,"sourceCode":"\t\treturn nil, nil, fmt.Errorf(\"failed to launch docker logger process %s: %v\", container.Container.ID, err)\n\t}\n\n\treturn dlogger, pluginClient, nil\n}\n\nfunc (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {\n\tif _, ok := d.tasks.Get(handle.Config.ID); ok {\n\t\treturn nil\n\t}\n\n\tvar handleState taskHandleState\n\tif err := handle.GetDriverState(&handleState); err != nil {\n\t\treturn fmt.Errorf(\"failed to decode driver task state: %v\", err)\n\t}\n\n\tdockerClient, err := d.getDockerClient()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get docker client: %w\", err)\n\t}\n\n\tdockerInfo, err := dockerClient.Info(d.ctx, mclient.InfoOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to fetch docker daemon info: %v\", err)\n\t}\n\n\tinfinityClient, err := d.getInfinityClient()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get docker long operations client: %w\", err)\n\t}\n\n\tcontainer, err := dockerClient.ContainerInspect(d.ctx, handleState.ContainerID, mclient.ContainerInspectOptions{})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to inspect container for id %q: %v\", handleState.ContainerID, err)\n\t}\n\n\th := &taskHandle{","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/driver.go#L237-L273","documentation":"After decoding the handle state, RecoverTask builds a Docker API client via d.getDockerClient(). If client creation fails (bad docker_endpoint, TLS setup failure, daemon init error), the error is wrapped with %w so the underlying cause is preserved and the task cannot be recovered.","triggerScenarios":"RecoverTask runs on a client whose Docker configuration is broken: docker_endpoint points to an unreachable socket/host, TLS cert/key/CA files are missing or unreadable, or the Docker client constructor rejects the config.","commonSituations":"Docker daemon stopped or uninstalled on the client after the task was started; nomad client runs in a container without /var/run/docker.sock mounted; docker_endpoint typo; TLS certs rotated/removed since the task originally started.","solutions":["Verify the Docker daemon is running (`systemctl status docker`) and the endpoint is reachable.","Check the client's docker_endpoint and TLS config; ensure cert/key/CA files exist and are readable by the Nomad user.","In containerized clients, mount /var/run/docker.sock into the Nomad container.","If the daemon was removed, reinstall Docker and reschedule the allocation."],"exampleFix":"// before: client config without socket access in container\n# docker run nomad-client  (no docker.sock)\n// after\n# docker run -v /var/run/docker.sock:/var/run/docker.sock nomad-client","handlingStrategy":"validation","validationCode":"cli, err := client.NewClientWithOpts(client.FromEnv)\nif err != nil {\n    return fmt.Errorf(\"docker client not constructible; check endpoint/TLS: %w\", err)\n}\nif _, err := cli.Ping(ctx); err != nil {\n    return fmt.Errorf(\"docker daemon unreachable: %w\", err)\n}","typeGuard":"func isDockerClientErr(err error) bool { return err != nil && strings.Contains(err.Error(), \"failed to get docker client\") }","tryCatchPattern":"if err := driver.RecoverTask(handle); err != nil {\n    if isDockerClientErr(err) {\n        logger.Warn(\"docker client init failed; verify daemon/endpoint\", \"err\", err)\n        // check DOCKER_HOST/socket, then retry recovery\n    } else {\n        return err\n    }\n}","preventionTips":["Health-check `docker info` before admitting tasks on the client.","Mount docker.sock or configure a valid docker_endpoint in containerized clients.","Keep TLS cert/key/CA files present and readable by the Nomad service user.","Alert on Docker daemon downtime so task recovery is attempted only when the daemon is up."],"tags":["docker","client-init","daemon-connection","nomad-driver"],"backgroundTag":"docker-daemon-unreachable","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}