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
.
If nginx is running in a container then your site is going to be 100% dead to the world while Docker isn't running. Users will get a connection error. When nginx is installed directly on your host you can serve a 503 maintenance page that doesn't depend on Docker or any containers running.
You can create an NGINX instance in a Docker container using the NGINX Open Source image from Docker Hub. This command creates a container named mynginx1 based on the NGINX image. The command returns the long form of the container ID, which is used in the name of log files; see Managing Logging.
Download the official Nginx Docker image from Docker Hub. Run the Nginx Docker image as a container. Copy the Docker container's Nginx config file to your local file system. Add proxy_pass entries that point to your backend origin servers.
To do this, we use the -v flag to map a folder from our local machine ( ~/docker-nginx/html ) to a relative path in the container ( /usr/share/nginx/html ). We can accomplish this by running the following command: sudo docker run --name docker-nginx -p 80:80 -d -v ~/docker-nginx/html:/usr/share/nginx/html nginx.
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.
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