Skip to content
Advertisement

flask app not running automatically from Dockerfile

My simple flask app is not automatically starting when I run in docker, though I have added CMD command correctly. I am able to run flask using python3 /app/app.py manually from container shell. Hence, no issue with code or command

FROM     ubuntu:latest
RUN      apt-get update
RUN      apt-get install -y gcc libffi-dev libssl-dev
RUN      apt-get install -y libxml2-dev xmlsec1
RUN      apt-get install -y python3-pip python3-dev
RUN      pip3 --no-cache-dir install --upgrade pip
RUN      rm -rf /var/lib/apt/lists/*
RUN      mkdir  /app
WORKDIR  /app
COPY     .  /app
RUN      pip3 install -r requirements.txt
EXPOSE   5000        
CMD     ["/usr/bin/python3", "/app/app.py"]

I run docker container as

docker run -it okta  /bin/bash

When I log in to docker container and run “ps -eaf” on Ubuntu shell of container, I do not see flask process running. So my question is why below line did not work in Dockerfile?

CMD     ["/usr/bin/python3", "/app/app.py"]

Advertisement

Answer

Running your docker container and passing the command /bin/bash is overriding the CMD [“/usr/bin/python3”, “/app/app.py”] in your Dockerfile.

CMD vs ENTRYPOINT Explained Here

Try changing the last line of your Dockerfile to

ENTRYPOINT ["/usr/bin/python3", "/app/app.py"]

Don’t forget to rebuild your image after changing.

Or… you can omit the /bin/bash from the end of your docker run command and see if your app.py starts up successfully.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement