0

I have followed this tutorial http://containertutorials.com/docker-compose/flask-simple-app.html which gives a valid Dockerfile, and the docker builds.

They say to run docker run -d -p 5000:5000 flask-sample-one to run the app, but this does not run the app, it just runs and exits. The correct command should keep the app running in the container so you can hit the server (localhost:5000). In their example they show a status of 'Up' which is not correct:

cchilders:~/web 
$ docker build -t flask-sample-one:latest .
Sending build context to Docker daemon 4.096 kB
Step 1/8 : FROM ubuntu:latest
 ---> 6a2f32de169d
Step 2/8 : RUN apt-get update -y
 ---> Using cache
 ---> 40ba52c006e7
Step 3/8 : RUN apt-get install -y python-pip python-dev build-essential
 ---> Using cache
 ---> ceeb0f2dc898
Step 4/8 : COPY . /app
 ---> Using cache
 ---> 4116b8a61dd0
Step 5/8 : WORKDIR /app
 ---> Using cache
 ---> 0115b7c1af92
Step 6/8 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> 821b5910bf3b
Step 7/8 : ENTRYPOINT python
 ---> Using cache
 ---> 6965a343433e
Step 8/8 : CMD app.py
 ---> Using cache
 ---> c840a89d0622
Successfully built c840a89d0622

cchilders:~/web 
$ docker run -d -p 5000:5000 flask-sample-one
055e9ebe5a633b042e432c07f225ac373cdcad34b4a2c61cd366507691e3ad0a

cchilders:~/web 
$ docker ps -a
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS                     PORTS                           NAMES
055e9ebe5a63        flask-sample-one          "python app.py"          5 seconds ago       Exited (1) 4 seconds ago                                   distracted_joliot

Each time I run it it exits. How can you run a container to stay active? Thank you

  • 1
    What do that container's logs say? It's likely that there's an error, which is causing the container to exit prematurely. – EEAA Apr 18 '17 at 13:58
  • 1
    Your flask app runs on your machine outside of Docker right? I think that container base python will be python2.7 - which might cause failures if your flask app is expecting python3. – tobyd Apr 18 '17 at 14:00
  • that was it, there is docker logs [id] – codyc4321 Apr 18 '17 at 14:14
  • you can post answer if you want – codyc4321 Apr 18 '17 at 14:15
0

The tutorial had a syntax error "From" I didn't notice. To solve a container that fails to run, use docker logs [container_id]

https://docs.docker.com/engine/admin/logging/view_container_logs/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.