Should I pack nginx in the same container as Django when deploying with Docker Swarm?

We are going to port our current Nginx / Gunicorn / Django stack to Docker and deploy it for high availability using Docker Swarm. One solution we struggled with was whether to host Nginx in the same container as Gunicorn / Django. Here are the scenarios and ways to view them:

Scenario 1 . Put Nginx in the application container. This runs counter to the “each service has its own container” methodology, but it allows Nginx to communicate directly with Gunicorn via a unix socket instead of a port. This is obviously not huge, but worth mentioning. Key benefits are listed below. A potential drawback here is the additional overhead of having too many Nginx instances (please consider this).

Scenario 2: Put Nginx in your own container. Although this follows the aforementioned methodology, it seems more erroneous. In the Docker Swarm scenario, the distribution of the Nginx and App containers is likely to not be uniform. Some sites may have more Nginx containers, while others have more application containers (and possibly even 0 Nginx containers). This means that Nginx will finish reverse proxying the application container on the other host completely.

Now I am sure that Docker Swarm supports special configurations in which at least one Nginx container should work on each node, but it looks like an anti-pattern. Even so, is it worth it to spend more on Scenario 1?

+4
1

, docker one container for one process. () , nginx, .

, django :

  • nginx (, )
  • gunicorn uwsgi
  • django

nginx , . ubuntu: 16.04/debian: jessie, nginx-full, ~ 100 . ( ).

, , nginx ( -).

+4

Source: https://habr.com/ru/post/1662304/


All Articles