简体   繁体   中英

/var/run/docker.sock: No such file or directory

1) I am running a docker container with following cmd :

$ 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 :

$ 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 :

$ ./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 :

$ 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 :

$ 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 :

$ 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. 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.

curl --unix-socket /var/run/docker.sock http://docker/containers/json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM