{"record":{"id":"f4ef71942e77343c","repo":"Billionmail/BillionMail","slug":"failed-to-update-billionmail-hostname-in-postfix-c","errorCode":null,"errorMessage":"failed to update BILLIONMAIL_HOSTNAME in postfix container: %v","messagePattern":"failed to update BILLIONMAIL_HOSTNAME in postfix container: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/domains/domains.go","lineNumber":126,"sourceCode":"\t\t\t\tActive:    1,\n\t\t\t})\n\t\t}\n\n\t\t// attempt update hostname in .env file\n\t\thostname := public.MustGetDockerEnv(\"BILLIONMAIL_HOSTNAME\", \"\")\n\n\t\tif hostname == \"\" || hostname == \"mail.example.com\" {\n\t\t\terr = public.SetDockerEnv(\"BILLIONMAIL_HOSTNAME\", public.FormatMX(domain.Domain))\n\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to update BILLIONMAIL_HOSTNAME in .env file: %v\", err)\n\t\t\t}\n\n\t\t\t// update postfix environment parameter\n\t\t\t_, err = public.DockerApiFromCtx(ctx).ExecCommandByName(ctx, consts.SERVICES.Postfix, []string{\"bash\", \"-c\", fmt.Sprintf(\"sed -i '/^BILLIONMAIL_HOSTNAME=/d' /postfix.sh && sed -i '/^#!\\\\/bin\\\\/bash/a BILLIONMAIL_HOSTNAME=%s' /postfix.sh\", public.FormatMX(domain.Domain))}, \"root\")\n\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to update BILLIONMAIL_HOSTNAME in postfix container: %v\", err)\n\t\t\t}\n\n\t\t\t// restart postfix service\n\t\t\terr = public.DockerApiFromCtx(ctx).RestartContainerByName(ctx, consts.SERVICES.Postfix)\n\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to restart postfix container: %v\", err)\n\t\t\t}\n\t\t}\n\n\t\t// catchall\n\t\tif domain.Catchall != \"\" {\n\t\t\terr = setCatchall(ctx, domain.Domain, domain.Catchall)\n\t\t}\n\t\treturn err\n\t}\n\n\treturn err","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/domains/domains.go#L108-L144","documentation":"After updating .env, Add runs `sed` inside the Postfix container to replace the BILLIONMAIL_HOSTNAME line in /postfix.sh. This error wraps failure of the Docker exec (DockerApiFromCtx(...).ExecCommandByName on consts.SERVICES.Postfix). It means the Postfix container's hostname script could not be edited in-place.","triggerScenarios":"AddDomain on the first/default-hostname domain when the docker exec fails: Postfix container not running, exec driver unavailable, /postfix.sh missing inside the container, or Docker socket/daemon errors.","commonSituations":"Postfix container stopped or crashed during setup; container name mismatch after stack rename; minimal image lacking sed; Docker daemon restarted mid-deployment.","solutions":["Confirm the Postfix container is running: docker ps (name must match consts.SERVICES.Postfix)","Check the wrapped error for 'no such container' vs exec exit code","Verify /postfix.sh exists and contains the BILLIONMAIL_HOSTNAME line inside the container","Set BILLIONMAIL_HOSTNAME via docker compose env and recreate the postfix container as a fallback"],"exampleFix":"// before\n_, err = public.DockerApiFromCtx(ctx).ExecCommandByName(ctx, consts.SERVICES.Postfix, []string{\"bash\",\"-c\", fmt.Sprintf(\"sed -i ...\", ...)}, \"root\")\nif err != nil { return fmt.Errorf(\"failed to update BILLIONMAIL_HOSTNAME in postfix container: %v\", err) }\n// after\n_, err = public.DockerApiFromCtx(ctx).ExecCommandByName(ctx, consts.SERVICES.Postfix, []string{\"bash\",\"-c\", sedCmd}, \"root\")\nif err != nil {\n    logger.Errorf(ctx, \"postfix sed exec failed: %v\", err)\n    return fmt.Errorf(\"failed to update BILLIONMAIL_HOSTNAME in postfix container (is %s running?): %v\", consts.SERVICES.Postfix, err)\n}","handlingStrategy":"retry","validationCode":"running, err := public.DockerApiFromCtx(ctx).IsContainerRunning(ctx, consts.SERVICES.Postfix)\nif err != nil || !running { return fmt.Errorf(\"postfix container %s not running before exec\", consts.SERVICES.Postfix) }","typeGuard":null,"tryCatchPattern":"err := retry.Do(3, 2*time.Second, func() error {\n    _, err := public.DockerApiFromCtx(ctx).ExecCommandByName(ctx, consts.SERVICES.Postfix, sedArgs, \"root\")\n    return err\n})\nif err != nil { return fmt.Errorf(\"failed to update BILLIONMAIL_HOSTNAME in postfix container: %v\", err) }","preventionTips":["Wait for postfix container healthy before AddDomain proceeds to env patching","Pin the container name used by consts.SERVICES.Postfix to the compose service name","Verify sed exists in the postfix image after image upgrades","Test exec paths with docker compose exec postfix ls /postfix.sh"],"tags":["docker","postfix","exec","container"],"backgroundTag":"docker-exec-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}