{"record":{"id":"7c4013a646837377","repo":"hashicorp/nomad","slug":"failed-to-query-list-of-containers-s","errorCode":null,"errorMessage":"Failed to query list of containers: %s","messagePattern":"Failed to query list of containers: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/driver.go","lineNumber":1695,"sourceCode":"\t}\n\n\treturn ip, auto\n}\n\n// containerByName finds a running container by name, and returns an error\n// if the container is dead or can't be found.\nfunc (d *Driver) containerByName(name string) (*mclient.ContainerInspectResult, error) {\n\n\tdockerClient, err := d.getDockerClient()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tcontainers, err := dockerClient.ContainerList(d.ctx, mclient.ContainerListOptions{All: true})\n\tif err != nil {\n\t\td.logger.Error(\"failed to query list of containers matching name\",\n\t\t\t\"container_name\", name)\n\t\treturn nil, recoverableErrTimeouts(\n\t\t\tfmt.Errorf(\"Failed to query list of containers: %s\", err))\n\t}\n\n\t// container names with a / pre-pended to the Nomad generated container names\n\tcontainerName := \"/\" + name\n\tvar (\n\t\tshimContainer containerapi.Summary\n\t\tfound         bool\n\t)\nOUTER:\n\tfor _, shimContainer = range containers.Items {\n\t\td.logger.Trace(\"listed container\", \"names\", hclog.Fmt(\"%+v\", shimContainer.Names))\n\t\tfor _, name := range shimContainer.Names {\n\t\t\tif name == containerName {\n\t\t\t\td.logger.Trace(\"Found container\",\n\t\t\t\t\t\"container_name\", containerName, \"container_id\", shimContainer.ID)\n\t\t\t\tfound = true\n\t\t\t\tbreak OUTER\n\t\t\t}","sourceCodeStart":1677,"sourceCodeEnd":1713,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/driver.go#L1677-L1713","documentation":"containerByName lists Docker containers via ContainerList to find a container matching a Nomad-generated name. If the Docker API list call fails (daemon unreachable, timeout, permissions), the error is wrapped with recoverableErrTimeouts and returned to createContainer/CreateNetwork.","triggerScenarios":"Docker daemon down or restarting, socket permissions denied, API timeout under load, or network partition between Nomad and the Docker endpoint during createContainer or CreateNetwork.","commonSituations":"Docker service crash/OOM on the host, docker.sock permissions changed, Docker API rate limiting or slowness with many containers, upgrade of the Docker daemon mid-allocation.","solutions":["Check `docker ps` and `systemctl status docker` on the client host to confirm the daemon is healthy.","Retry the allocation — the error is wrapped as recoverable for timeouts, so rescheduling often succeeds once the daemon recovers.","Verify docker.sock permissions for the nomad user and DOCKER_HOST/socket configuration in the client's docker plugin config."],"exampleFix":"// before\nsudo docker ps   # fails: Cannot connect to the Docker daemon\n// after\nsudo systemctl restart docker\n# then reschedule: nomad job eval <job-id> or nomad alloc stop <alloc-id>","handlingStrategy":"retry","validationCode":"// preflight: confirm the daemon answers before scheduling\ncmd := exec.Command(\"docker\", \"info\")\nif err := cmd.Run(); err != nil { log.Fatal(\"docker daemon unreachable\") }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if errors.Is(err, context.DeadlineExceeded) || isTimeoutErr(err) {\n        time.Sleep(backoff); goto retry // recoverable per recoverableErrTimeouts\n    }\n    return err\n}","preventionTips":["Monitor Docker daemon health on client hosts (systemd unit + docker info probe)","Grant the nomad user correct docker.sock group permissions","Cap container counts / tune daemon to avoid API slowness under load"],"tags":["docker","nomad","daemon-unreachable","timeout"],"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"}