请考虑以下命令序列。当我尝试以普通用户或 root 身份连接到 docker 守护程序时,无法连接。当我使用 sudo(以普通用户和 root 身份)时,可以连接。这是为什么?
[john@mb:~]$ docker ps
Cannot connect to the Docker daemon at unix:///run/user/1000/docker.sock. Is the docker daemon running?
[john@mb:~]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
150fdfe05f3b nicolargo/glances:latest-full "/bin/sh -c '/venv/b…" 3 days ago Up 2 days 0.0.0.0:61208->61208/tcp, :::61208->61208/tcp, 61209/tcp glances
83c656bf1863 filebrowser/filebrowser "/filebrowser" 3 days ago Up 2 days (healthy) 0.0.0.0:8080->80/tcp, :::8080->80/tcp filebrowser
[john@mb:~]$ su root
Password:
[root@mb:/home/john]# docker ps
Cannot connect to the Docker daemon at unix:///run/user/1000/docker.sock. Is the docker daemon running?
[root@mb:/home/john]# sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
150fdfe05f3b nicolargo/glances:latest-full "/bin/sh -c '/venv/b…" 3 days ago Up 2 days 0.0.0.0:61208->61208/tcp, :::61208->61208/tcp, 61209/tcp glances
83c656bf1863 filebrowser/filebrowser "/filebrowser" 3 days ago Up 2 days (healthy) 0.0.0.0:8080->80/tcp, :::8080->80/tcp filebrowser
答案1
sudo
重置环境。su
不。
您的用户显然已将变量设置DOCKER_HOST
为unix:///run/user/1000/docker.sock
或将其放在 Docker 配置文件中。grep
fordocker.sock
可能是找到它的好方法。