[英]Unable to run Flask App using Docker in Windows-10
我已經安裝並配置了 docker(根據文檔),我正在嘗試使用tiangolo/uwsgi-nginx-flask:python3.8
構建一個燒瓶應用程序。 我已經構建了一個 hello-world 應用程序,並通過運行python manage.py
在本地對其進行了測試,應用程序運行成功。 鏈接到完整的代碼文件。
我的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 build --tag hello-world:test .
並將應用程序運行為: docker run -d -p 5000:5000 hello-world:test
成功。
但是,我無法在localhost:5000
或0.0.0.0:5000
或任何其他端口中打開應用程序。 應用程序正在運行,我可以從 CLI 中看到它:
但是,從瀏覽器無法訪問該頁面:
問題提到檢查IP地址:
docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" hungry_engelbart
>> <no value>
在此鏈接中找到了另一個解決方案,但目前不推薦使用docker-machine
。
我是 docker 的新手,但我嘗試按照本教程運行相同的東西,但遇到了類似的問題。
最后,我能夠解決這個問題。 我必須在 Windows 防火牆 > 高級設置 > 入站規則 > 新入inbound rules
下配置新的inbound rules
站規則。 創建一個允許一系列本地 IP 地址的新規則,在我的例子中是198.168.0.1:198.168.0.100
。 最后,您需要在注釋中@tentative 指出的0.0.0.0
處運行應用程序。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.