Nginx Proxies to Docker Container

You can see that the normally running container listens to the port 3000 in this case. The container will expose the port that is configured in your Dockerfile or the Dockerrun.aws.json according to the AWS documentation. The script with that logic that selects the port to expose is actually located at /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh. EB configures nginx to proxy port 80 to this exposed container port with this config file: /etc/nginx/conf.d/elasticbeanstalk-nginx-docker-upstream.conf

Configure Docker Container Server Concurrency

Configuring nginx to proxy to another webserver is pretty typically. Unicorn and puma are commonly use and they are configured so that they have multiple processes or threads to handle concurrency. In the EB case, nginx proxies to the server within the docker container itself. Knowing this, it is important for scaling reasons that the docker container server is configured for concurrency properly. You’ll want to configure your container to have the right number of workers or threads to maximize the RAM and CPU on the instance efficiently. EB is usually used to run only docker container on each AWS instance. So it is crucial that we configure that docker container’s server to run more than 1 process or thread or else we’ll be likely wasting resources and worse not scale.

Each application is different in how it consumes CPU and uses RAM so you’ll have to play with it. Here are simple examples for unicorn and puma.

ELB

Lastly, EB sets up and ELB so traffic gets load balanced to port 80 on each instances in the environment. So the overall routing goes: client -> ELB > nginx -> docker.

Curl the ELB endpoint to make sure that it’s working all the way from the ELB to nginx to docker.