简体   繁体   中英

Why docker container doesn't run

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

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

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