Auto-reloading of code changes with Django development in Docker with Gunicorn

后端 未结 4 667
粉色の甜心
粉色の甜心 2020-12-13 04:04

I\'m using a Docker container for Django development, and the container runs Gunicorn with Nginx. I\'d like code changes to auto-load, but the only way I can get them to loa

4条回答
  •  悲&欢浪女
    2020-12-13 04:29

    Since I never found a desirable solution consider this interesting hack. Posting here I wanted to see if anyone has similar/good/bad experiences with this "work around".

    To make code reload locally for development I simply created a View that immediately calls exit(). The exit will crash Django and a reload will occur where code changes are available. The reboot takes a fraction of a second and can be done via a tab in the browser, a requests.get call, or any other similar call. The reload is not automatic but it does skip any Docker lag such as a restart.

    When the exit is called you will see the PID increment (if tailing logs):

    web    | [2019-07-15 18:29:52 +0000] [22] [INFO] Worker exiting (pid: 22)
    web    | [2019-07-15 18:29:52 +0000] [24] [INFO] Booting worker with pid: 24
    

    I hope this helps others and/or gets feed back on this approach.

提交回复
热议问题