gpt4 book ai didi

docker -/var/run/docker.sock:没有这样的文件或目录

转载 作者:行者123 更新时间:2023-12-02 20:02:18 34 4
gpt4 key购买 nike

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)在容器内,我有一个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)运行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)我有一个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)在容器内,我得到:
$ 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)如果我从容器中退出并在主机上运行相同的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...]

谁能让我知道上述步骤3/5中可能的错误原因。还有什么可以尝试进一步调试它的。谢谢。

最佳答案

它仅适用于节点。如果希望它在容器内运行,请确保使用volumes hostPath方法挂载/ var / run。

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

关于docker -/var/run/docker.sock:没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52592078/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com