Should you install nginx inside docker?

15k views Asked by At

I am wondering about the pros and cons of having or not having nginx inside your docker image. There are plenty of tutorials on how to install nginx on docker, but what I am asking is, should you or should you not?

Should you install nginx on the docker host, and have it point to the individual running containers (which could be running rainbows etc.)? or

Should you install another nginx layer inside your containers?

I don't see any benefit of having another nginx inside docker containers, but then I wonder why there are so many tutorials on that, as if that's the common sense, and I am not getting the common sense, which frustrates me.

edit:

The less config per container the better it is for me. If there's tight coupling between the nginx container and the app container behind it, then it is certainly not the solution I am looking for, and beats the purpose of having containers in the first place. This is why I am leaning toward having nginx installed on the Docker host.

If we are to have an nginx container, the container should be independent of the apps. App-specific configuration, such as port numbers and ip addresses, number of worker processes, client_max_body_size should not be configured into the container unless they can be customized when executing docker run.

1

There are 1 answers

2
Peter Lyons On

This may get closed as opinion based, but for what it's worth my opinion is that docker should be involved in networking up to the transport layer (TCP/UDP) but no higher (HTTP). Thus I would say no you should not install nginx as a reverse proxy directly on your docker host directly and yes you should install nginx within your container(s) if you want the features nginx provides.

You could decide you want an nginx container in front of each of your applications (this seems most in harmony with the overall idea of containerization and separation and not sharing things), or one nginx container to reverse proxy several apps hosted in containers on the same host (simpler overall, but more tightly coupled and perhaps less harmonious with docker's philosophy). You could also take the phusion style and put both your application and it's nginx in the same container, which provides a nice coherent unit, but otherwise is against the common case of 1 process tree per container.