{"record":{"id":"7097503601e1c8d0","repo":"slimtoolkit/slim","slug":"docker-socket-not-found","errorCode":null,"errorMessage":"docker socket not found","messagePattern":"docker socket not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/docker/dockerclient/client.go","lineNumber":130,"sourceCode":"\n\t\tsocketInfo.Address = UnixSocketAddr\n\t\tlog.Debugf(\"dockerclient.GetUnixSocketAddr(): found => %s\", jsonutil.ToString(socketInfo))\n\t\treturn socketInfo, nil\n\t}\n\n\tuserDockerSocket := UserDockerSocket()\n\tif _, err := os.Stat(userDockerSocket); err == nil {\n\t\tsocketInfo, err := getSocketInfo(userDockerSocket)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tsocketInfo.Address = fmt.Sprintf(\"unix://%s\", userDockerSocket)\n\t\tlog.Debugf(\"dockerclient.GetUnixSocketAddr(): found => %s\", jsonutil.ToString(socketInfo))\n\t\treturn socketInfo, nil\n\t}\n\n\treturn nil, fmt.Errorf(\"docker socket not found\")\n}\n\n// New creates a new Docker client instance\nfunc New(config *config.DockerClient) (*docker.Client, error) {\n\tvar client *docker.Client\n\tvar err error\n\n\tnewTLSClient := func(host string, certPath string, verify bool, apiVersion string) (*docker.Client, error) {\n\t\tvar ca []byte\n\n\t\tcert, err := os.ReadFile(filepath.Join(certPath, \"cert.pem\"))\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tkey, err := os.ReadFile(filepath.Join(certPath, \"key.pem\"))\n\t\tif err != nil {\n\t\t\treturn nil, err","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/docker/dockerclient/client.go#L112-L148","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install/start Docker so the daemon socket exists (systemctl start docker).","Mount the host socket into the container: -v /var/run/docker.sock:/var/run/docker.sock.","Point the client to your actual socket path if you use a non-default one (rootless: /run/user/<uid>/docker.sock).","If the daemon is remote/TCP-only, configure the client for the tcp:// host instead of unix socket discovery."],"exampleFix":"// before\ndocker run --rm my-tool // no socket inside\n// after\ndocker run --rm -v /var/run/docker.sock:/var/run/docker.sock my-tool","handlingStrategy":"validation","validationCode":"func dockerSocketExists() bool {\n    for _, p := range []string{\"/var/run/docker.sock\", \"/run/docker.sock\"} {\n        if _, err := os.Stat(p); err == nil {\n            return true\n        }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"cli, err := dockerclient.New(cfg)\nif err != nil {\n    if strings.Contains(err.Error(), \"docker socket not found\") {\n        return fmt.Errorf(\"docker unavailable: mount /var/run/docker.sock or set DOCKER_HOST: %w\", err)\n    }\n    return err\n}","preventionTips":["Mount -v /var/run/docker.sock:/var/run/docker.sock when running inside containers.","Install/verify Docker is installed and running before invoking the client.","Support DOCKER_HOST / non-default socket paths for rootless and Docker Desktop setups.","Add an environment preflight check for the socket before starting the app."],"tags":["go","docker","socket","environment"],"backgroundTag":"docker-socket-not-found","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}