Laimonas Sutkus
Laimonas Sutkus

Reputation: 3627

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. 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). Please find an illustrated example. enter image description here

Does it even make any difference?

Upvotes: 1

Views: 678

Answers (1)

Siyu
Siyu

Reputation: 12139

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. 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. 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.

Third, the complexity of setting up nginx is also to be considered. Personally I don't think nginx is easy enough to setup and debug. 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.

Upvotes: 1

Related Questions