简体   繁体   中英

How to prevent a flask docker container from exiting when there are syntax errors?

I have a docker container running flask that is sharing it's /app directory. This is supposed to be a dev environment but sometimes when I'm working I will unknowingly save a python file with syntax errors which immediately causes the app to throw errors and exit. That's fine but since the docker container exits, I cannot reboot the flask app after fixing things. Any way to prevent this?

Here's the flask container, I'm guessing the CMD commands can be configured to prevent this:

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

You set that policy when you start the container using docker:

docker run -d --restart always myimage:latest

Or using docker-compose file you can add restart: always to your service definition.

  mycontainer:
    image: myimage:latest
    restart: always
    env: 
       ...

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