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

Initializing Docker Swarm


Now that we have a base configuration of setting up a Docker host, let us move to the next level and set up a Docker Swarm cluster automatically:

  1. First, we need a way to store the Docker Swarm join token securely. We will use chef-vault as a way to store the token. To be able to use chef-vault, we will simply add it as a dependency of our cookbook in cookbooks/dockerhost/metadata.rb:
name 'dockerhost'
# ...
version '0.1.0'

depends 'docker', '~> 4.7'
depends 'chef-vault', '~> 3.1' # update here
  1. Next, we will create a Chef recipe for initializing the manager node in cookbooks/dockerhost/recipes/manager.rb:
include_recipe 'dockerhost::base'

execute 'init swarm' do
  command 'docker swarm init'
  not_if 'docker info -f "{{.Swarm.LocalNodeState}}" | egrep "^active"'
end

Note that we used Chef's guard clauses to prevent docker swarm init from running multiple times. This makes our Chef recipe idempotent.

  1. Back in our base recipe, cookbooks/dockerhost/recipes/base.rb...