Auto reloading flask server on Docker

前端 未结 4 2243
南笙
南笙 2020-12-16 11:44

I want my flask server to detect changes in code and reload automatically. I\'m running this on docker container. Whenever I change something, I have to build and up again t

4条回答
  •  旧时难觅i
    2020-12-16 12:16

    Flask supports code reload when in debug mode as you've already done. The problem is that the application is running on a container and this isolates it from the real source code you are developing. Anyway, you can share the source between the running container and the host with volumes on your docker-compose.yaml like this:

    Here is the docker-compose.yaml

    version: "3"
    services:
      web:
        build: ./web
        ports: ['5000:5000']
        volumes: ['./web:/app']
    

    And here the Dockerfile:

    FROM python:alpine
    
    EXPOSE 5000
    
    WORKDIR app
    
    COPY * /app/
    
    RUN pip install -r requirements.txt
    
    CMD python app.py
    

提交回复
热议问题