slimtoolkit/slim · error

docker socket not found

Error message

docker socket not found

What it means

GetUnixSocketAddr discovers the Docker daemon's unix socket by probing well-known paths (e.g. /var/run/docker.sock and alternate socket paths). When none of the candidate sockets exist, it returns this error with no socket info. The library throws it because a unix-socket Docker client cannot be constructed without a socket file.

Source

Thrown at pkg/docker/dockerclient/client.go:130

		socketInfo.Address = UnixSocketAddr
		log.Debugf("dockerclient.GetUnixSocketAddr(): found => %s", jsonutil.ToString(socketInfo))
		return socketInfo, nil
	}

	userDockerSocket := UserDockerSocket()
	if _, err := os.Stat(userDockerSocket); err == nil {
		socketInfo, err := getSocketInfo(userDockerSocket)
		if err != nil {
			return nil, err
		}

		socketInfo.Address = fmt.Sprintf("unix://%s", userDockerSocket)
		log.Debugf("dockerclient.GetUnixSocketAddr(): found => %s", jsonutil.ToString(socketInfo))
		return socketInfo, nil
	}

	return nil, fmt.Errorf("docker socket not found")
}

// New creates a new Docker client instance
func New(config *config.DockerClient) (*docker.Client, error) {
	var client *docker.Client
	var err error

	newTLSClient := func(host string, certPath string, verify bool, apiVersion string) (*docker.Client, error) {
		var ca []byte

		cert, err := os.ReadFile(filepath.Join(certPath, "cert.pem"))
		if err != nil {
			return nil, err
		}

		key, err := os.ReadFile(filepath.Join(certPath, "key.pem"))
		if err != nil {
			return nil, err

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Install/start Docker so the daemon socket exists (systemctl start docker).
  2. Mount the host socket into the container: -v /var/run/docker.sock:/var/run/docker.sock.
  3. Point the client to your actual socket path if you use a non-default one (rootless: /run/user/<uid>/docker.sock).
  4. If the daemon is remote/TCP-only, configure the client for the tcp:// host instead of unix socket discovery.

Example fix

// before
docker run --rm my-tool // no socket inside
// after
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock my-tool
Defensive patterns

Strategy: validation

Validate before calling

func dockerSocketExists() bool {
    for _, p := range []string{"/var/run/docker.sock", "/run/docker.sock"} {
        if _, err := os.Stat(p); err == nil {
            return true
        }
    }
    return false
}

Try / catch

cli, err := dockerclient.New(cfg)
if err != nil {
    if strings.Contains(err.Error(), "docker socket not found") {
        return fmt.Errorf("docker unavailable: mount /var/run/docker.sock or set DOCKER_HOST: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling GetUnixSocketAddr (directly or via New, HasImage, ListImages, BuildEmptyImage, SaveImage, GetVolumeInfo) on a machine where no Docker socket file exists at any of the probed locations.

Common situations: Docker not installed in the container/VM; running inside a container without mounting /var/run/docker.sock; using a non-standard DOCKER_HOST or rootless Docker socket path; Docker Desktop socket at a non-default location.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/7097503601e1c8d0. Report an issue: GitHub.