简体   繁体   中英

Unable to run Flask App using Docker in Windows-10

I've installed and configured docker (as per documentation) and I am trying to build a flask application using tiangolo/uwsgi-nginx-flask:python3.8 . I've built a hello-world application, and have tested it locally by running python manage.py and the application runs successfully. Link to full Code-File .

My docker version and installation is as below:

在此处输入图片说明

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" ]

I built the application with docker build --tag hello-world:test . and running the application as: docker run -d -p 5000:5000 hello-world:test successfully.

在此处输入图片说明

However, I'm unable to open the application in localhost:5000 or 0.0.0.0:5000 or any other port. The application is running, as I can see it from the CLI:

在此处输入图片说明

But, from browser the page is not reachable:

在此处输入图片说明

The question mentions to check the IP address:

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" hungry_engelbart
>> <no value>

Found another solution at this link , but docker-machine is currently deprecated.

I'm new to docker, but I have tried to run the same thing following this tutorial , but faced similar issues.

Finally, I am able to solve this. I had to configure a new inbound rules under Windows Firewall > Advanced Settings > Inbound Rules > New Inbound Rules. Create a new rule that will allow a range of local IP addresses, which in my case was 198.168.0.1:198.168.0.100 . Finally, you need to run the application at 0.0.0.0 as pointed by @tentative in the comments. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM