Docker Community Forums

Share and learn in the Docker community.

Docker compose exited with code 0 with flask


(Andykw) #1

Each time I’m doing a docker-compose up, I have this error

Starting flaskcomposesample_web_1 ... done
Attaching to flaskcomposesample_web_1
flaskcomposesample_web_1 exited with code 0

This is my docker-compose.yml file

web:
  build: ./web
  ports:
  - "5000:5000"
  volumes:
  - .:/code
  tty: true

This is my Dockerfile

FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN apt-get install -y python3-pip
# RUN pip3 install flask
RUN pip3 install -r requirements.txt
ENTRYPOINT ["python3.6"]
CMD ["app.py"]

And this my app.py

import flask
app = flask.Flask(__name__)

@app.route('/')
def hello_world():
    return 'Flask Dockerized'

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

From what I see, everything is correct.

Do you have any ideas of the why I’m getting a code 0?

Cheers


(Martin Terp) #2

things you can try:

1. docker ps -a, get the ID, and then do: docker logs ID, maybe that will provide you with some help

2. try and run the container in the background: docker-compose up -d , maybe you are the one who exists it.


(Andykw) #3

Hi Martin

I tried

docker ps -a

This is what I have

daf8af512251 flaskcomposesample_web “python3.6 app.py” 2 days ago Exited (0) 5 minutes ago

I did that docker logs daf8af512251

Nothing was returned.


(Martin Terp) #4

did you try the: docker compose up -d ?


(Andykw) #5

A friend helped me to find the solution

The script app.py has an incorrect indentation.

It should be that way

import flask
app = flask.Flask(__name__)

@app.route('/')
def hello_world():
    return 'Flask Dockerized'

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

The last part

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

must be on the same line as the function


(Andykw) #6

yes but it still exited

But a friend helped me with the issue. It was an indentation on the python script.

Thanks Martin


(Martin Terp) #7

ah! python :stuck_out_tongue_winking_eye: