OrbStack 与 Docker Desktop 造成 docker.sock 冲突问题

本文最后更新于:2023-05-30 22:01 星期二

OrbStack 与 Docker Desktop 造成 docker.sock 冲突问题

OrbStack 集成了docker与Linux, 类似于虚拟机的APP

在终端会出现如下问题。

1
2
3
4
5
$ docker ps
Cannot connect to the Docker daemon at unix:///Users/***/.docker/run/docker.sock. Is the docker daemon running?
#
$ docker ps
Cannot connect to the Docker daemon at unix:///Users/***/.orbstack/run/docker.sock. Is the docker daemon running?

解决方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
docker context use desktop-linux
docker context use orbstack

$ docker context ls
NAME DESCRIPTION DOCKER ENDPOINT ERROR
default Current DOCKER_HOST based configuration unix:///var/run/docker.sock
desktop-linux * unix:///Users/**/.docker/run/docker.sock
orbstack OrbStack unix:///Users/**/.orbstack/run/docker.sock

# OrbStack 将默认docker.sock 链接到OrbStack 的docker.sock
# sudo ln -s ~/.docker/run/docker.sock /var/run/docker.sock

$ docker context

Usage: docker context COMMAND

Manage contexts

Commands:
create Create a context
export Export a context to a tar archive FILE or a tar stream on STDOUT.
import Import a context from a tar or zip file
inspect Display detailed information on one or more contexts
ls List contexts
rm Remove one or more contexts
show Print the name of the current context
update Update a context
use Set the current docker context

Run 'docker context COMMAND --help' for more information on a command.

#------------------------
## 需要安装 jq 命令
alias dkd="jq '.currentContext=\"desktop-linux\"' ~/.docker/config.json > ~/.docker/config.json_new && rm ~/.docker/config.json && mv ~/.docker/config.json_new ~/.docker/config.json"
alias dko="jq '.currentContext=\"orbstack\"' ~/.docker/config.json > ~/.docker/config.json_new && rm ~/.docker/config.json && mv ~/.docker/config.json_new ~/.docker/config.json"

造成原因 ~/.docker/config.json文件 的currentContext变量值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$ tree -NL 1  ~/.docker  ~/.docker/contexts/meta
/Users/***/.docker
├── application-template
├── bin
├── buildx
├── canary.json
├── certs.d
├── cli-plugins
├── config.json #需要修改的文件
├── contexts
├── daemon.json
├── devenvironments
├── features.json
├── run
└── scan
/Users/***/.docker/contexts/meta
├── 2d89b732b01a00a2d1675ed3cee9fd0f965daadf90603c989dd3afd4569c6896 #currentContext 变量的值
└── fe9c6bd7a66301f49ca9b6a70b217107cd1284598bfc254700c989b916da791e #currentContext 变量的值



$ cat ~/.docker/config.json | jq
{
"auths": {},
"credsStore": "desktop",
"credHelpers": {
"asia.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"us.gcr.io": "gcloud"
},
"experimental": "enabled",
"stackOrchestrator": "swarm",
"currentContext": "orbstack" ##currentContext 导致 找不到 docker.sock
}


OrbStack 与 Docker Desktop 造成 docker.sock 冲突问题
https://blog.dekun.wang/blog/a32b1858.html
作者
Wang Dekun
发布于
2023-05-30 22:01 星期二
更新于
2023-06-01 22:41 星期四
许可协议