[英]django in docker not detecting SIGINT
This is a funny stackover flow question, because I have an answer, but the answer is a few years old.这是一个有趣的 stackover flow 问题,因为我有一个答案,但答案是几年前的。 I can't find much content which is new, yet it seems like it would be quite high profile.
我找不到很多新内容,但似乎它会非常引人注目。
I am using docker-compose to start a few containers.我正在使用 docker-compose 来启动几个容器。 Two of them use standard postgres and redis images.
其中两个使用标准的 postgres 和 redis 图像。 The others are django 2.2.9 (and celery) This is a development environment, and I start them with docker compose, like this:
其他的是django 2.2.9(和celery)这是一个开发环境,我用docker compose启动它们,像这样:
command: ./manage.py runserver 0.0.0.0:80
docker-compose stop sends a SIGINT. docker-compose stop 发送一个 SIGINT。 The redis and postgres containers exit quickly.
redis 和 postgres 容器快速退出。 the django containers don't.
Django 容器没有。 docker-compose stop loses patience and kills them.
docker-compose stop 失去耐心并杀死他们。
(and pycharm has infinite patience currently, and doesn't send a kill until I force it). (而且 pycharm 目前有无限的耐心,并且在我强制执行之前不会发送杀戮)。
This post from 2015 referring to Django 1.9 ( http://blog.lotech.org/fix-djangos-runserver-when-run-under-docker-or-pycharm.html ) says that这篇 2015 年的帖子提到了 Django 1.9 ( http://blog.lotech.org/fix-djangos-runserver-when-run-under-docker-or-pycharm.html ) 说
"The quick fix is to specifically listen for SIGINT and SIGTERM in your manage.py, and sys.kill() when you get them. So modify your manage.py to add a signal handler:"
“快速修复是在你的 manage.py 和 sys.kill() 中专门监听 SIGINT 和 SIGTERM,当你得到它们时。所以修改你的 manage.py 以添加一个信号处理程序:”
and it says how.它说如何。 The fix to change manage.py to catch SIGINT works and it's a handful of lines, although it doesn't work for celery which has its own startup.
更改 manage.py 以捕获 SIGINT 的修复程序有效并且只有几行,尽管它不适用于拥有自己的启动的 celery。 So I can carry forward my own version of of manage.py and fix celery, but really is this still how to fix this?
所以我可以继承我自己的 manage.py 版本并修复 celery,但这真的仍然是如何解决这个问题的吗?
I see the the dockerfile could have我看到 dockerfile 可能有
STOPSIGNAL SIGINT
but it doesn't make and difference, I suppose because the entry point is managed by docker-compose.但这并没有什么区别,我想是因为入口点是由 docker-compose 管理的。
Use the list variant of command
:使用
command
的列表变体:
command: ["./manage.py", "runserver", "0.0.0.0:80"]
See https://hynek.me/articles/docker-signals/ for details why.有关原因的详细信息,请参阅https://hynek.me/articles/docker-signals/ 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.