简体   繁体   English

Docker - 每个单独的我的服务容器都有单独的 nginx 容器

[英]Docker - separate nginx container for every separate my service container

Following Docker best practices - a container should be created with a "single responsibility" principle in mind - it makes a good idea to have nginx and some-my-custom service in separate docker containers.遵循 Docker 最佳实践——创建容器时应牢记“单一责任”原则——将 nginx 和一些我的自定义服务放在单独的 Docker 容器中是一个好主意。 But the question is - if i run in an autoscaled/loadbalanced environment where i have at least 2-3 running copies of the same container - should I have a separate nginx container cluster for my every custom services cluster or should I have one nginx containers cluster for the whole infrastructure (but simply more instances).但问题是 - 如果我在自动缩放/负载平衡环境中运行,在该环境中我至少有 2-3 个相同容器的运行副本 - 我应该为每个自定义服务集群拥有一个单独的 nginx 容器集群,还是应该拥有一个 nginx 容器整个基础设施的集群(但只是更多的实例)。 Please find an illustrated example.请找到一个插图示例。 在此处输入图片说明

Does it even make any difference?它甚至有什么区别吗?

I don't think there is an absolute answer to this question, so I'm just throwing my current (random) thoughts.我认为这个问题没有绝对的答案,所以我只是抛出我目前(随机)的想法。

First, it depends on what you use nginx for.首先,这取决于您使用 nginx 的目的。 If it's used to host webpacked web site, then sure you need one nginx for each of your frontend service, combined with worker_processes in nginx.conf , you have an easy load balancing solution for the frontend.如果它用于托管 webpacked 网站,那么确保您的每个frontend服务都需要一个 nginx,结合nginx.conf worker_processes ,您就有了一个简单的前端负载平衡解决方案。 If you want to use it a reverse proxy for load balancing, one instance is enough for a small cluster (when it grows bigger, you can add more to form a multi-tier load balancer).如果你想用它做负载均衡的反向代理,一个实例足够一个小集群(当它变大时,你可以添加更多,形成一个多层负载均衡器)。

Second swarm actually has a native load balancer that sort of works out of the box.第二个 swarm 实际上有一个本地负载均衡器,可以开箱即用。

Third, the complexity of setting up nginx is also to be considered.第三,设置nginx的复杂度也是要考虑的。 Personally I don't think nginx is easy enough to setup and debug.我个人认为 nginx 不太容易设置和调试。 Modern solutions like traefik.io are easier to use and built with clustering in mind, and come with extra features like automatic https configuration via lets'encrypt.像 traefik.io 这样的现代解决方案更易于使用,并且在构建时考虑了集群,并带有额外的功能,例如通过 let'encrypt 自动配置 https。

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

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