[英]/var/run/docker.sock: No such file or directory
1) I am running a docker container with following cmd : 1)我正在使用以下cmd运行docker容器:
$ docker run --name=xyz -d -e CONTAINER_NAME=xyz -e SSH_PORT=22 -e NWMODE=HOST -e XDG_RUNTIME_DIR=/run/user/0 --net=host -v /mnt:/mnt -v /dev:/dev -v /etc/sysconfig/network-scripts:/etc/sysconfig/network-scripts -v /:/hostroot/ -v /etc/hostname:/etc/host_hostname -v /etc/localtime:/etc/localtime -v /var/run/docker.sock:/var/run/docker.sock --privileged=true cf3681e04bfb
2) Inside the container, i have a.py where i create a docker client as shown below : 2)在容器内,我有一个a.py,在其中创建一个docker客户端,如下所示:
$ cat a.py
#!/usr/bin/python
from docker import Client as DC
dc = DC('unix://var/run/docker.sock', version='auto')
3) Running a.py gives following error : 3)运行a.py会出现以下错误:
$ ./a.py /usr/local/lib/python2.7/dist-packages/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown. warnings.warn(warning, RequestsDependencyWarning) Traceback (most recent call last): File "./a.py", line 5, in <module> dc = DC('unix://var/run/docker.sock', version='auto') File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 99, in __init__ self._version = self._retrieve_server_version() File "/usr/local/lib/python2.7/dist-packages/docker/client.py", line 124, in _retrieve_server_version 'Error while fetching server API version: {0}'.format(e) docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', error(2, 'No such file or directory'))
4) i have a docker daemon running with unix domain socket in listening mode : 4)我有一个docker守护进程在监听模式下与unix域套接字一起运行:
$ netstat --listen | grep docker unix 2 [ ACC ] STREAM LISTENING 11146 /var/run/docker.sock unix 2 [ ACC ] STREAM LISTENING 17471 /var/run/docker/libcontainerd/docker-containerd.sock unix 2 [ ACC ] STREAM LISTENING 17648 /run/docker/libnetwork/02833519b1ad75ad062f6443ab5c10e5d9c783c22beb98d8b8b41b2ee082cfcd.sock
5) Inside the container, i get : 5)在容器内,我得到:
$ curl --verbose --unix-socket /var/run/docker.sock http:/containers/json * Trying /var/run/docker.sock... * Immediate connect fail for /var/run/docker.sock: No such file or directory * Closing connection 0 curl: (7) Couldn't connect to server
6) If i exit from the container and run same curl cmd on the host machine, it works fine : 6)如果我从容器中退出并在主机上运行相同的curl cmd,则工作正常:
$ exit //coming out from the container $ curl --unix-socket /var/run/docker.sock http:/containers/json [{"Id":"3973df106fcfae0d1f5b4be23b6e5f265421aa932053433f5e9e7bc9574d753a","Names"......multiple key-value pairs here...]
can anyone let me know what may be the probable cause of error in steps 3/5 above. 谁能让我知道上述步骤3/5中可能的错误原因。 What else can be tried to debug it further.
还有什么可以尝试进一步调试它的。 thanks.
谢谢。
It will work only on nodes. 它仅适用于节点。 If you want it to work inside container make sure you mount /var/run using volumes hostPath method.
如果希望它在容器内运行,请确保使用volumes hostPath方法挂载/ var / run。
curl --unix-socket /var/run/docker.sock http://docker/containers/json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.