2

I built I Flask application and I am trying to make it run on a Docker file.

I run two commands:

1)

docker build -t my-api-docker:latest .

2)

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

1 Answer 1

4

It should not bind with container localhost i.e

Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

change the CMD in Dockerfile

CMD [ "flask", "run", "--host=0.0.0.0" ]

or

CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"] 

or replace the inside your code

app.run(host='0.0.0.0').
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.