2

I am trying to run a flask application in a docker on windows, and python 3.7.

This is my flask application:

app.py:

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
   #some lines of code
   return render_template('home.html', url=url, host='0.0.0.0')

if __name__ == '__main__':
   app.run(debug=True, host='0.0.0.0')

Then I created a dockerfile.txt as a DockerFile and put the following contents inside:

FROM python:3.7
MAINTAINER <<Your Name>>
RUN apt-get update -y && \
   apt-get install -y python3-pip python3-dev
COPY ./requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip3 install -t lib -r requirements.txt
COPY . /app
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]

Then I run the following comments in command prompt:

docker build -t flask-image:latest .
docker run -d -p 5000:5000 --name name-container1 flask-image

My problem is that after docker ps -a I see container name-container1 is exited. But have no idea why???

This is output:

CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                          PORTS               NAMES
d925f21f165c        flask-image         "python3 app.py"    About a minute ago   Exited (1) About a minute ago                       name-container1
ElisaFo
  • 130
  • 13

1 Answers1

0

Most likely PYTHONPATH is not setup in Docker. Instead of RUN pip3 install -t lib -r requirements.txt, just install the requirements as RUN pip3 install -r requirements.txt

Jakub Czaplicki
  • 1,787
  • 2
  • 28
  • 50
  • Now it gives me this error: ModuleNotFoundError: No module named 'pandas_datareader' – ElisaFo Dec 17 '18 at 20:59
  • Are you still trying to run the code snipped in the original question ? IThere's no `pandas_datareader` reader there. Unless you've added some more code that imports `pandas_datareader` in that case, is there pandas_datareader in requirements.txt ? – Jakub Czaplicki Dec 18 '18 at 11:24