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

huangapple go评论85阅读模式
英文:

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

问题

我想连接到在我的本地机器(Apple M2)上运行的Docker服务器。当我运行docker ps时,它显示所有正在运行的容器,这意味着Docker服务器正在运行,并且我可以通过Docker桌面进行验证。但是,当我尝试通过Docker Go SDK连接时,它无法连接。

以下是命令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                                      

请注意,这是我翻译的内容,不包括代码部分。

英文:

I want to connect to my Docker server running on my local machine (Apple M2). When I run docker ps it shoes all the containers running which means Docker server is running, and I could verify that by going Docker desktop. But when I try to connect it via Docker Go SDK, it can't 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

Here is 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                                      

答案1

得分: 1

我通过进入Docker设置 > 高级,并启用Docker sock来修复了它。

英文:

I have fixed it by going to Docker Settings > Advanced and enable Docker sock.

huangapple
  • 本文由 发表于 2023年5月20日 20:06:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76295142.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定