gpt4 book ai didi

python - docker-compose up 不转发端口

转载 作者:行者123 更新时间:2023-11-28 21:35:08 25 4
gpt4 key购买 nike

我有以下文件。当我运行 docker-compose up -d 并执行到 docker 容器中时,我能够运行 http://127.0.0.1:5000并取回结果。我从主机返回:

user@ubuntu:~/projects/grip/glm-plotter$ curl -v http://localhost:5000
* Rebuilt URL to: http://localhost:5000/
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.58.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

如果我在没有 -d 的情况下运行 docker-compose 命令,它会启动,但从一个单独的终端我也会得到空结果。

docker ps(不带 -d 运行时)

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
237b0a7f8710 glm-plotter_web "python3 glm-plotter…" 16 minutes ago Up 24 seconds 0.0.0.0:5000->5000/tcp glm-plotter_web_1

我不确定该进程是否应该列在“docker-proxy”下:

user@ubuntu:~$ sudo netstat -tulpn | grep 5000 
tcp6 0 0 :::5000 :::* `LISTEN 13785/docker-proxy`

docker 文件

FROM library/python:3.6-stretch
RUN apt-get update && apt-get install -y python3
RUN apt-get install -y python3-pip
RUN apt-get install -y build-essential

COPY requirements.txt /
RUN pip3 install --trusted-host pypi.org -r /requirements.txt
RUN pip3 install --upgrade numpy
ADD ./glm-plotter /code
WORKDIR /code
RUN ls .
CMD ["python3", "glm-plotter.py"]

docker-compose.yml

version: "3"
services:
web:
volumes:
- ~/.aws:/root/.aws
build: .
ports:
- "5000:5000"

最佳答案

您的 glm-plotter.py 仅在容器中的 localhost 上监听。您的应用程序必须监听容器中的所有接口(interface) - TCP 主机 0.0.0.0,而不仅仅是 locahost/127.0.0.1 - 您需要修复 python 代码。

这是一个常见问题 - flask 示例:flask is working inside container but not when I port forward it

关于python - docker-compose up 不转发端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52605306/

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