为什么我不能从docker中运行的python服务器得到正确的回复

2024-04-20 01:14:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我在docker中运行了一个用python3编写的服务器,但是我无法正确得到回复,为什么

服务器代码:

import socket


s = socket.socket()
s.bind(("0.0.0.0",10000))
s.listen(5)
while True:
    cur, add = s.accept()
    cur.sendall(b"hello")
    cur.close()

docker-compose.yml:

version: '2'
services:

  python:
    build:
      context: .
      dockerfile: python_Dockerfile
    ports:
      - "10000:10000"

python\u Dockerfile:

FROM python:3
WORKDIR /app
RUN mkdir /app/data
COPY test.py /app
CMD ["python", "-u", "test.py"]

Tags: docker代码pytestimportdockerfile服务器true