Billionmail/BillionMail · error

failed to connect to Docker API: %v

Error message

failed to connect to Docker API: %v

What it means

After fixing permissions the function must restart the rspamd container, which requires a Docker API client. This error means docker.NewDockerAPI() failed — the app could not establish a connection to the Docker daemon socket.

Source

Thrown at core/internal/service/domains/domains.go:996

		if err != nil {
			return err
		}
		if info.IsDir() {
			return os.Chmod(path, 0755)
		}
		if strings.HasSuffix(path, ".private") || strings.HasSuffix(path, ".pub") {
			return os.Chmod(path, 0644)
		}
		return nil
	})
	if err != nil {
		return fmt.Errorf("failed to change DKIM file permissions: %v", err)
	}

	// 6. Restart rspamd service
	dk, err := docker.NewDockerAPI()
	if err != nil {
		return fmt.Errorf("failed to connect to Docker API: %v", err)
	}
	defer dk.Close()

	err = dk.RestartContainerByName(ctx, consts.SERVICES.Rspamd)
	if err != nil {
		return fmt.Errorf("failed to restart rspamd container: %v", err)
	}

	return nil
}

View on GitHub (pinned to fc36c76c05)

Solutions

  1. Confirm the Docker daemon is running (systemctl status docker)
  2. Bind-mount /var/run/docker.sock into the app container and set the correct DOCKER_HOST
  3. Add the running user to the docker group or grant socket access
  4. Verify the docker client library/SDK version matches the daemon API version
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat("/var/run/docker.sock"); err != nil {
	return fmt.Errorf("docker socket not available: %v", err)
}

Try / catch

if err := RepairDKIMSigningConfig(ctx); err != nil && strings.Contains(err.Error(), "failed to connect to Docker API") {
	log.Printf("ensure docker socket is mounted and daemon is up: %v", err)
}

Prevention

When it happens

Trigger: docker.NewDockerAPI() returns an error: /var/run/docker.sock missing or not mounted, DOCKER_HOST misconfigured, daemon not running, or socket permission denied for the process user.

Common situations: App runs in a container without the Docker socket bind-mounted; the user is not in the docker group; Docker daemon stopped on host; rootless Docker socket path differs from the default.

Related errors


AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05). Data as JSON: /api/errors/e3df009dcf0c108e. Report an issue: GitHub.