简体   繁体   English

在使用Docker Swarm进行部署时,是否应将nginx打包到与Django相同的容器中?

[英]Should nginx be packed into the same container as Django when deploying with Docker Swarm?

We are looking to move our current Nginx/Gunicorn/Django stack into Docker, and deploy it for high availability using Docker Swarm. 我们希望将当前的Nginx / Gunicorn / Django堆栈移植到Docker中,并使用Docker Swarm将其部署为高可用性。 One of the decisions we have been struggling with is whether or not to place Nginx in the same container as Gunicorn/Django. 我们一直在努力的决定之一是将Nginx放在与Gunicorn / Django相同的容器中。 Here are the scenarios and how we view them: 以下是场景以及我们如何查看它们:

Scenario 1 : Place Nginx in the app's container. 场景1 :将Nginx放在应用程序的容器中。 This goes against the "each service has its own container" methodology, but it allows Nginx to communicate with Gunicorn directly through a unix socket instead of a port. 这违反了“每个服务都有自己的容器”方法,但它允许Nginx直接通过unix socket而不是端口与Gunicorn进行通信。 This obviously isn't huge but it's worth mentioning. 这显然不是很大,但值得一提。 The main advantages are listed below. 主要优点如下。 A potential disadvantage here is having extra overhead from too many Nginx instances (please weigh in on this). 这里的一个潜在缺点是从太多的Nginx实例中获得额外的开销(请对此进行权衡)。

Scenario 2: Place Nginx in its own container. 场景2:将Nginx放在自己的容器中。 Though this follows the aforementioned methodology, it seems more flawed. 虽然这遵循上述方法,但似乎更有缺陷。 In a Docker Swarm scenario, the distribution of Nginx and App containers will likely not be uniform. 在Docker Swarm场景中,Nginx和App容器的分布可能不一致。 Some nodes may end up with more Nginx containers, while others have more app containers (and possibly even 0 Nginx containers). 一些节点最终可能有更多Nginx容器,而其他节点有更多的app容器(甚至可能有0个Nginx容器)。 This means that Nginx would end up reverse-proxying an app container on a different host entirely. 这意味着Nginx最终会完全反向代理不同主机上的应用容器。

Now I'm sure Docker Swarm supports special configurations that say at least one Nginx container must be running on each node, but this strikes me as an anti-pattern. 现在我确定Docker Swarm支持特殊配置,这些配置说每个节点上必须至少运行一个Nginx容器,但这让我觉得它是反模式。 Even in that instance, is it worth the effort over Scenario 1? 即使在那种情况下,是否值得在场景1中付出努力?

Based on production experience, it's better to counterpart rule from docker docs one container for one process . 根据生产经验,最好从docker docs对应one container for one process规则来one container for one process You're shipping a (micro-)service with docker image, and if it's required to have nginx in it, you include it. 您正在发送带有泊坞窗图像的(微)服务,如果需要在其中包含nginx,则将其包含在内。

So basically for django app there are: 所以基本上对于django应用程序有:

  1. nginx (eg: for static files) nginx(例如:用于静态文件)
  2. gunicorn or uwsgi gunicorn或uwsgi
  3. django code itself django代码本身

Don't see any perfomance issue on adding nginx to container, but little note on docker image size. 将nginx添加到容器时没有看到任何性能问题,但很少注意到docker图像大小。 On ubuntu:16.04/debian:jessie by adding nginx-full you increase your image size for around ~100mb. 在ubuntu上:16.04 / debian:jessie通过添加nginx-full你可以增加你的图像大小~100mb左右。 (some overhead on first pulling image). (首先拉动图像的一些开销)。

So it's not controversal to second scenario, because you can also add nginx behind your docker image for balancing purpose (or proxy_pass managing). 因此,对于第二种情况,这不是争议,因为您还可以在您的docker映像后面添加nginx以实现平衡目的(或proxy_pass管理)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM