gpt4 book ai didi

python - 在 docker 容器内导入 socketio 失败?

转载 作者:行者123 更新时间:2023-12-01 02:26:33 24 4
gpt4 key购买 nike

我已经构建了一个 docker 镜像,每个使用该镜像的容器都将运行一个名为“run.py”的应用程序。

run.py 使用socket.io:导入socketio

docker运行后出现以下错误:

Traceback (most recent call last):
File "run.py", line 1, in <module>
import socketio
File "/usr/local/lib/python2.7/site-packages/socketio/__init__.py", line 8, in <module>
from .zmq_manager import ZmqManager
File "/usr/local/lib/python2.7/site-packages/socketio/zmq_manager.py", line 5, in <module>
import eventlet.green.zmq as zmq
File "/usr/local/lib/python2.7/site-packages/eventlet/__init__.py", line 10, in <module>
from eventlet import convenience
File "/usr/local/lib/python2.7/site-packages/eventlet/convenience.py", line 6, in <module>
from eventlet.green import socket
File "/usr/local/lib/python2.7/site-packages/eventlet/green/socket.py", line 21, in <module>
from eventlet.support import greendns
File "/usr/local/lib/python2.7/site-packages/eventlet/support/greendns.py", line 69, in <module>
setattr(dns.rdtypes.IN, pkg, import_patched('dns.rdtypes.IN.' + pkg))
File "/usr/local/lib/python2.7/site-packages/eventlet/support/greendns.py", line 59, in import_patched
return patcher.import_patched(module_name, **modules)
File "/usr/local/lib/python2.7/site-packages/eventlet/patcher.py", line 119, in import_patched
*additional_modules + tuple(kw_additional_modules.items()))
File "/usr/local/lib/python2.7/site-packages/eventlet/patcher.py", line 93, in inject
module = __import__(module_name, {}, {}, module_name.split('.')[:-1])
File "/usr/local/lib/python2.7/site-packages/eventlet/support/dns/rdtypes/IN/WKS.py", line 24, in <module>
_proto_udp = socket.getprotobyname('udp')
socket.error: protocol not found

我的 Dockerfile 提供了一个官方的 python 镜像,它安装了下面描述的要求,并在/etc 中添加了文件协议(protocol)。最后一步是按照 https://github.com/eventlet/eventlet/issues/370 中的建议完成的。 .

#parent image: official python runtime
FROM python:2.7-slim
#workdir: /app
WORKDIR /app
#copy the current directory contents into the container in the path /app
ADD . /app
ADD protocols /etc
#install packages contained in the text
RUN pip install -r requirements.txt
#make port 80 available to the world (outside the container)
EXPOSE 8081
#execute a py app
CMD ["python", "run.py"]

要求是:

Netbase
python-socketio
eventlet
socketIO-client

最佳答案

不使用Python的slim版本,使用完整 Python 版本。

您的 dockerfile 将如下所示:

#parent image: official python runtime
FROM python:2.7
#workdir: /app
WORKDIR /app
#copy the current directory contents into the container in the path /app
ADD . /app
ADD protocols /etc
#install packages contained in the text
RUN pip install -r requirements.txt
#make port 80 available to the world (outside the container)
EXPOSE 8081
#execute a py app
CMD ["python", "run.py"]

关于python - 在 docker 容器内导入 socketio 失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47335331/

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