gpt4 book ai didi

python - docker 组成 : OSError: [Errno 99] Cannot assign requested address

转载 作者:行者123 更新时间:2023-12-04 18:44:32 29 4
gpt4 key购买 nike

我正在使用 docker-compose up运行 python 文件,但是,有错误信息:

matching_server_1  | Traceback (most recent call last):
matching_server_1 | File "server.py", line 65, in <module>
matching_server_1 | server = TCPServer((HOST, PORT), RequestHandler)
matching_server_1 | File "/usr/local/lib/python3.7/socketserver.py", line 452, in __init__
matching_server_1 | self.server_bind()
matching_server_1 | File "/usr/local/lib/python3.7/socketserver.py", line 466, in server_bind
matching_server_1 | self.socket.bind(self.server_address)
matching_server_1 | OSError: [Errno 99] Cannot assign requested address

但是程序运行良好 python3 server.py没有 docker 。

项目结构如下:
root
|—docker-compose.yml
|—matching_engine
|—Dockerfile
|-server.py (main)
|-.......

我的 Dockerfile 是:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /src
WORKDIR /src
ADD requirements.txt /src/
RUN pip install -r requirements.txt
ADD . /src/

我的 docker-compose.yml 是:
version: '2'

services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: passw0rd
POSTGRES_USER: postgres
POSTGRES_DB: EXCHANGEMACHINE
volumes:
- /var/lib/docker/volumes/data-volume:/var/lib/postgresql/data
restart: always
matching_server:
build: ./matching_engine
user: nobody
command: bash -c "python3 server.py"
volumes:
- ./matching_engine:/src
ports:
- "12345:12345"
expose:
- "12345"
depends_on:
- db

以及在 server.py 中报告错误的代码是:
if __name__ == '__main__':
HOST = '0.0.0.0'
PORT = 12345
server = TCPServer((HOST, PORT), RequestHandler)
server.serve_forever()

在这种情况下出了什么问题?谢谢!

最佳答案

尝试添加您的 matching_server 服务

links: 
- db

并删除暴露:“12345”

关于python - docker 组成 : OSError: [Errno 99] Cannot assign requested address,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55505460/

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