{"record":{"id":"50aa93c17b5138df","repo":"Billionmail/BillionMail","slug":"failed-to-create-docker-client-v","errorCode":null,"errorMessage":"failed to create Docker client: %v","messagePattern":"failed to create Docker client: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/dockerapi/dockerapi.go","lineNumber":34,"sourceCode":"\t\"time\"\n\n\t\"github.com/docker/docker/api/types/container\"\n\t\"github.com/docker/docker/api/types/filters\"\n\t\"github.com/docker/docker/client\"\n\t\"github.com/docker/docker/pkg/stdcopy\"\n)\n\n// DockerAPI struct\ntype DockerAPI struct {\n\tclient     *client.Client\n\tcontainers map[string]bool\n}\n\n// NewDockerAPI creates a new DockerAPI instance\nfunc NewDockerAPI() (*DockerAPI, error) {\n\tcli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create Docker client: %v\", err)\n\t}\n\n\treturn &DockerAPI{\n\t\tclient:     cli,\n\t\tcontainers: make(map[string]bool),\n\t}, nil\n}\n\n// StartContainer starts a container\nfunc (d *DockerAPI) StartContainer(ctx context.Context, containerID string) error {\n\treturn d.client.ContainerStart(ctx, containerID, container.StartOptions{})\n}\n\n// StopContainer stops a container\nfunc (d *DockerAPI) StopContainer(ctx context.Context, containerID string) error {\n\ttimeout := gconv.Int(10 * time.Second)\n\treturn d.client.ContainerStop(ctx, containerID, container.StopOptions{\n\t\tTimeout: &timeout,","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/dockerapi/dockerapi.go#L16-L52","documentation":"NewDockerAPI builds a Docker SDK client using client.FromEnv (DOCKER_HOST, certs, etc.) with API version negotiation. If the SDK cannot construct a client from the environment, construction fails with this wrapped error before any Docker call is attempted.","triggerScenarios":"Invalid DOCKER_HOST URL format; bad TLS cert/key paths in DOCKER_CERT_PATH; a client.FromEnv option error such as unreadable certificates; in-process failures creating the HTTP client.","commonSituations":"DOCKER_HOST set to a malformed value (missing tcp:// or bad unix:// path); certificate files removed or permissions changed; running in an environment with a partially configured Docker context.","solutions":["Check DOCKER_HOST, DOCKER_TLS_VERIFY, DOCKER_CERT_PATH env values are valid and files exist","Run `docker info` in the same environment to validate the Docker client config","Clear bogus DOCKER_* env vars so client.FromEnv falls back to the default unix socket","Inspect the wrapped cause (%v) for the exact option that failed (usually cert loading)"],"exampleFix":"// before\nexport DOCKER_HOST=\"192.168.1.5:2375\" // malformed\n// after\nexport DOCKER_HOST=\"tcp://192.168.1.5:2375\"","handlingStrategy":"try-catch","validationCode":"if dh := os.Getenv(\"DOCKER_HOST\"); dh != \"\" {\n    if u, err := url.Parse(dh); err != nil || u.Scheme == \"\" {\n        return fmt.Errorf(\"invalid DOCKER_HOST: %q\", dh)\n    }\n}","typeGuard":null,"tryCatchPattern":"api, err := dockerapi.NewDockerAPI()\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to create Docker client\") {\n        return fmt.Errorf(\"docker unavailable, check DOCKER_* env: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate DOCKER_HOST URL format before startup","Ensure DOCKER_CERT_PATH files exist with correct permissions","Smoke-test with `docker info` in the deploy environment","Avoid exporting stray DOCKER_* vars in app containers"],"tags":["docker","configuration","environment"],"backgroundTag":"docker-client-init-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}