{"record":{"id":"47f895ee291e528f","repo":"Billionmail/BillionMail","slug":"failed-to-connect-to-docker-api-v","errorCode":null,"errorMessage":"Failed to connect to Docker API: %v","messagePattern":"Failed to connect to Docker API: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/domains/domains.go","lineNumber":543,"sourceCode":"\nfunc getDKIMRecordWithKeySize(domain, selector string, keySize int, validateImmediate bool) (record v1.DNSRecord, err error) {\n\t// Create DKIM directory\n\tdkimPath := public.AbsPath(filepath.Join(consts.RSPAMD_LIB_PATH, \"dkim\", domain))\n\n\t// Check if directory exists\n\tif !public.IsDir(dkimPath) {\n\t\t_ = os.MkdirAll(dkimPath, 0755)\n\t}\n\n\t// Check if DKIM private and public key files exist\n\tdkimPriPath := filepath.Join(dkimPath, selector+\".private\")\n\tdkimPubPath := filepath.Join(dkimPath, selector+\".pub\")\n\n\tvar dk *docker.DockerAPI\n\n\tdk, err = docker.NewDockerAPI()\n\tif err != nil {\n\t\terr = fmt.Errorf(\"Failed to connect to Docker API: %v\", err)\n\t\treturn\n\t}\n\tdefer dk.Close()\n\n\t// Generate new keys if they don't exist\n\tif !public.FileExists(dkimPriPath) || !public.FileExists(dkimPubPath) {\n\t\tmutex.Lock()\n\t\tdefer mutex.Unlock()\n\n\t\tvar res *v2.ExecResult\n\t\tres, err = dk.ExecCommandByName(context.Background(), consts.SERVICES.Rspamd, []string{\"rspamadm\", \"dkim_keygen\", \"-s\", selector, \"-b\", fmt.Sprintf(\"%d\", keySize), \"-d\", domain, \"-k\", fmt.Sprintf(\"/var/lib/rspamd/dkim/%s/%s.private\", domain, selector)}, \"root\")\n\t\tif err != nil {\n\t\t\terr = fmt.Errorf(\"Failed to generate DKIM key pair: %v\", err)\n\t\t\treturn\n\t\t}\n\n\t\tif res != nil {\n\t\t\t_, err = public.WriteFile(dkimPubPath, res.Output)","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/domains/domains.go#L525-L561","documentation":"getDKIMRecordWithKeySize needs a Docker client (docker.NewDockerAPI) to exec rspamadm key generation inside the Rspamd container. This error wraps client-construction failure — typically the Docker socket is unreachable or DOCKER_HOST is misconfigured. No DKIM record can be generated or read without it.","triggerScenarios":"GetDKIMRecord, GetDKIMShortRecord, or RepairDKIMSigningConfig when docker.NewDockerAPI() fails: /var/run/docker.sock missing or permission-denied, Docker daemon stopped, or DOCKER_HOST pointing to an unreachable endpoint (common when running the app outside the deployment container).","commonSituations":"App container not mounted with the Docker socket; user not in the docker group (permission denied on socket); DOCKER_HOST=tcp://... to a dead daemon; running the binary on a host without Docker during development.","solutions":["Verify Docker is running: systemctl status docker / docker info","Check the Docker socket is mounted and writable in the app container (e.g. /var/run/docker.sock volume + group permissions)","Check DOCKER_HOST env is correct if using a remote daemon","Run the app inside the deployment environment where Docker access is provisioned"],"exampleFix":"// before\ndk, err = docker.NewDockerAPI()\nif err != nil { err = fmt.Errorf(\"Failed to connect to Docker API: %v\", err); return }\n// after\ndk, err = docker.NewDockerAPI()\nif err != nil {\n    err = fmt.Errorf(\"Failed to connect to Docker API (check /var/run/docker.sock and DOCKER_HOST): %v\", err)\n    return\n}\n// precheck before calling\ndi, derr := docker.NewDockerAPI(); if derr != nil { return fmt.Errorf(\"docker unavailable: %w\", derr) }","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(\"/var/run/docker.sock\"); err != nil {\n    return fmt.Errorf(\"docker socket not mounted: %v\", err)\n}\nif os.Getenv(\"DOCKER_HOST\") != \"\" {\n    return fmt.Errorf(\"DOCKER_HOST set to %s — verify daemon reachability\", os.Getenv(\"DOCKER_HOST\"))\n}","typeGuard":null,"tryCatchPattern":"dk, err := docker.NewDockerAPI()\nif err != nil {\n    return fmt.Errorf(\"Failed to connect to Docker API: %v\", err) // bubble up; retry later once daemon recovers\n}\ndefer dk.Close()","preventionTips":["Mount /var/run/docker.sock into the app container with proper group permissions","Add the app user to the docker group in the image","Run DKIM operations only inside the deployed environment, not bare-metal dev hosts","Monitor docker info in healthchecks"],"tags":["docker","dkim","connection","socket"],"backgroundTag":"docker-socket-unavailable","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"}