Auto reloading flask server on Docker

前端 未结 4 2235
南笙
南笙 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:10

    This is my example:

    version: "3.8"
    
    services:
      local-development:
        build:
          context: .
          dockerfile: Dockerfiles/development.Dockerfile
        ports:
          - "5000:5000"
        volumes:
          - .:/code
    
    from flask import Flask
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def hello_world():
        return "hello world"
    
    
    if __name__ in "__main__":
        app.run(host="0.0.0.0", port=5000, debug=True)
    

    debug=True enables Flask to change as your code changes.

    Docker already plugs into your fs events to change the code "in the container".

提交回复
热议问题