【发布时间】:2021-06-20 19:09:26
【问题描述】:
我已经安装并配置了 docker(根据文档),我正在尝试使用 tiangolo/uwsgi-nginx-flask:python3.8 构建一个烧瓶应用程序。我已经构建了一个 hello-world 应用程序,并通过运行 python manage.py 在本地对其进行了测试,并且该应用程序运行成功。 Link to full Code-File.
我的docker版本和安装如下:
Dockerfile:
FROM tiangolo/uwsgi-nginx-flask:python3.8
ENV INSTALL_PATH /usr/src/helloworld
RUN mkdir -p $INSTALL_PATH
# install net-tools
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
net-tools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# set working directory
WORKDIR $INSTALL_PATH
# setup flask environment
# install all requirements
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
# copy all files and folder to docker
COPY . .
# run the application in docker environment
CMD [ "python", "./manage.py" ]
我使用docker build --tag hello-world:test . 构建了应用程序,并将应用程序运行为:docker run -d -p 5000:5000 hello-world:test 成功。
但是,我无法在 localhost:5000 或 0.0.0.0:5000 或任何其他端口打开应用程序。应用程序正在运行,我可以从 CLI 中看到它:
但是,从浏览器无法访问该页面:
question 提到要检查 IP 地址:
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" hungry_engelbart
>> <no value>
在this link 找到了另一个解决方案,但docker-machine 目前已被弃用。
我是 docker 新手,但我尝试在 this tutorial 之后运行相同的东西,但遇到了类似的问题。
【问题讨论】:
-
您是否尝试过将地址显式设置为
0.0.0.0,就像this answer 中的一样?您将进行此更改 here 并将localhost替换为0.0.0.0。 -
是的,
localhost:5000和0.0.0.0:5000都试过了,得到了相同的响应。
标签: python windows docker flask