Home >Backend Development >Golang >Go Docker SDK: Unable to connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Go Docker SDK: Unable to connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

WBOY
WBOYforward
2024-02-12 16:54:061259browse

Go Docker SDK:无法连接到位于 unix:///var/run/docker.sock 的 Docker 守护进程。 docker 守护进程是否正在运行?

Question content

I want to connect to a docker server running on my local computer (apple m2). When I run docker ps it starts all the running containers which means the docker server is running and I can verify this by going to docker desktop. But when I try to connect it via docker go sdk it fails to connect.

❯ go run main.go
2023/05/20 17:34:15 cannot connect to the docker daemon at unix:///var/run/docker.sock. is the docker daemon running?
exit status 1

This is the output of the command docker context ls:

❯ docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                  KUBERNETES ENDPOINT                ORCHESTRATOR
default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                      https://35.186.144.128 (default)   swarm
desktop-linux *     moby                                                          unix:///Users/xencodes/.docker/run/docker.sock                                      

Workaround

I fixed the issue by going to Docker Settings > Advanced and enabling Docker sock.

The above is the detailed content of Go Docker SDK: Unable to connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete