Bobcares

Elastic beanstalk docker Nginx | All About

by | Oct 27, 2022

Today let’s discuss on Elastic beanstalk docker Nginx article by our Docker Hosting Support Service at Bobcares.

Elastic beanstalk Docker on Upstart

Elastic beanstalk docker Nginx
Initially, the docker container is always kept running by the upstart config “/etc/init/eb-docker.conf”. If you kill the process, it will just come back up.

# docker ps
CONTAINER ID        IMAGE                              COMMAND                CREATED             STATUS              PORTS               NAMES
163ebbeedede        aws_beanstalk/current-app:latest   "/bin/sh -c docker/b   19 hours ago        Up 19 hours         3000/tcp            hopeful_brattain
# docker stop 163ebbeedede
163ebbeedede
# docker ps
CONTAINER ID        IMAGE                              COMMAND                CREATED             STATUS              PORTS               NAMES
163ebbeedede        aws_beanstalk/current-app:latest   "/bin/sh -c docker/b   19 hours ago        Up 1 seconds        3000/tcp            hopeful_brattain
#

If you really want to stop the service, you  will need to do so by upstart: stop eb-docker.

# docker ps
CONTAINER ID        IMAGE                              COMMAND                CREATED             STATUS              PORTS               NAMES
163ebbeedede        aws_beanstalk/current-app:latest   "/bin/sh -c docker/b   19 hours ago        Up 34 seconds       3000/tcp            hopeful_brattain
# stop eb-docker
eb-docker stop/waiting
# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
# start eb-docker
eb-docker start/running, process 11090
# docker ps
CONTAINER ID        IMAGE                              COMMAND                CREATED             STATUS              PORTS               NAMES
163ebbeedede        aws_beanstalk/current-app:latest   "/bin/sh -c docker/b   19 hours ago        Up 1 seconds        3000/tcp            hopeful_brattain
#

Nginx Proxies to Docker Container

You can see that the normal running container listens to port 3000. The container will show up in the port that configured in your Dockerfile or the Dockerrun.aws.json according to the AWS document.

The script with that logic selects the port to show its actual location at "/opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh". Elastic Beanstalk configures Nginx to proxy port 80 to the exposed container port with a config file “/etc/nginx/conf.d/elasticbeanstalk-nginx-docker-upstream.conf”

Directly we can curl the docker port.

# curl -s -v -o /dev/null 172.17.0.9:3000 2>&1  | grep '< HTTP'
< HTTP/1.1 200 OK

We can also curl Nginx port 80 to check the proxy working from Nginx to the container.

# curl -s -v -o /dev/null localhost:80 2>&1  | grep '< HTTP'
< HTTP/1.1 200 OK

Configure Docker Container Server Concurrency

Configuring the Nginx proxy to another web server is pretty typical. In this Elastic beanstalk case, Nginx proxies to the server within the docker container. It’s important for scaling reasons how the docker container has configured for concurrency.

Configure the container for the right number of workers or threads to maximize the RAM and CPU on the instance efficiently. Elastic Beanstalk, usually use to run only the docker containers on each AWS instance.

So it is important to configure the docker container’s server to run more than 1 process or thread or else we will be likely wasting resources and worse not scale. Each application is different in how the CPU and RAM consumes.

Elastic beanstalk

Lastly, Elastic Beanstalk sets up an ELB, so traffic gets load balanced to port 80 on each instance in the environment. So the overall routing goes: client >> ELB >> Nginx >> docker.

Now curl the ELB endpoint, just to make sure that it’s working from the ELB to Nginx to docker.

$ curl -s -v -o /dev/null "http://your-custom-endpoint.elasticbeanstalk.com" 2>&1 | grep '< HTTP'
< HTTP/1.1 200 OK

[Looking for a solution to another query? We are just a click away.]

Conclusion

To conclude, Elastic Beanstalk supports the deployment of web applications from Docker containers. Configure the docker container’s server to run more than 1 process or thread.

PREVENT YOUR SERVER FROM CRASHING!

Never again
lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server
24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.