I built I Flask application and I am trying to make it run on a Docker file.
I run two commands:
docker build -t my-api-docker:latest .
docker run -p 5000:5000 my-api-docker
Both are run without errors and the output on terminal is the classic Flask:
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
HOWEVER
If I visit: http://localhost:5000 if show that:
The page is not working
requirements.txt
Flask==1.1.1
requests==2.20.1
pandas==0.23.4
Dockerfile
FROM python:3.7
RUN pip install --upgrade pip
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY . /app
EXPOSE 5000
CMD [ "flask", "run" ]
The flask app is serving on localhost:5000 IN the container. this localhost is not the same as your localhost and is not served to the outside. If you want to service to be available outside of the container you must listen to correct ips.
e.g. all: