Book Image

Docker High Performance - Second Edition

By : Allan Espinosa, Russ McKendrick
Book Image

Docker High Performance - Second Edition

By: Allan Espinosa, Russ McKendrick

Overview of this book

Docker is an enterprise-grade container platform that allows you to build and deploy your apps. Its portable format lets you run your code right from your desktop workstations to popular cloud computing providers. This comprehensive guide will improve your Docker work?ows and ensure your application's production environment runs smoothly. This book starts with a refresher on setting up and running Docker and details the basic setup for creating a Docker Swarm cluster. You will then learn how to automate this cluster by using the Chef server and cookbooks. After that, you will run the Docker monitoring system with Prometheus and Grafana, and deploy the ELK stack. You will also learn best practices for optimizing Docker images. After deploying containers with the help of Jenkins, you will then move on to a tutorial on using Apache JMeter to analyze your application's performance. You will learn how to use Docker Swarm and NGINX to load-balance your application, and how common debugging tools in Linux can be used to troubleshoot Docker containers. By the end of this book, you will be able to integrate all the optimizations that you have learned and put everything into practice in your applications.
Table of Contents (16 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Index

Balancing load with NGINX


Now that we have a pool of Docker applications to forward traffic to, we can prepare our load balancer. In this section, we will briefly cover NGINX, a popular web server that has high concurrency and performance. It is commonly used as a reverse proxy to forward requests to more dynamic web applications, such as the Node.js one we wrote earlier. By configuring NGINX to have multiple reverse proxy destinations, such as our pool of Docker applications, it will balance the load of requests coming to it across the pool.

The following steps will deploy NGINX to our Docker Swarm cluster for load balancing:

  1. First, let's prepare an NGINX configuration file called nginx.conf:
events { }

http {
  resolver 127.0.0.11 valid=5s ipv6=off;

  server {
    listen 80;
    location / {
      set $backend application;
      proxy_pass http://$backend:8000;
    }
  }
}

Note that we used NGINX's DNS service discovery to send traffic to our application via its network alias application...