We are looking to move our current Nginx/Gunicorn/Django stack into Docker, and deploy it for high availability using 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. Here are the scenarios and how we view them:
Scenario 1: Place Nginx in the app's container. 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. 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).
Scenario 2: Place Nginx in its own container. 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. Some nodes may end up with more Nginx containers, while others have more app containers (and possibly even 0 Nginx containers). This means that Nginx would end up reverse-proxying an app container on a different host entirely.
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. Even in that instance, is it worth the effort over Scenario 1?
Based on production experience, it's better to counterpart rule from docker docs 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.
So basically for django app there are:
Don't see any perfomance issue on adding nginx to container, but little note on docker image size. On ubuntu:16.04/debian:jessie by adding nginx-full you increase your image size for around ~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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With