In the Docker World, orchestration is the most important part of the ecosystem. Docker Swarm, Kubernetes, Apache Mesos .. all of these are orchestrators, every one of them has its own philosophy, use cases, and architecture. Rancher is a tool built to simplify Docker orchestration and management.

Painless Docker is a practical guide to master Docker and its ecosystem based on real-world examples.

Through this online training, you will learn how to use Docker in development and production environments and the DevOps pipeline between them in order to build modern microservices applications.

Painless Docker Cover

This tutorial is part of this book and through it, we are going to discover how to use Rancher in order to create a scalable Wordpress application.

Rancher Architecture

In Rancher, everything (like containers, networks or images ) is an API resource with a process lifecycle. Containers, images, networks, and accounts are all API resources with their own process lifecycles.

Rancher is built on the top of containers:

A web UI

An API

A server that manages Rancher Agents

A database

A machine microservice

The docker-machine binary

Rancher Server Architecture

When you run Rancher using docker run rancher/server ... the RancherAPI + Rancher Process Server + The Database + Machine Microservice are processes that live inside this container.

Note that the docker-machine binary is also living in the same container but only runs when it is called by the API.

Rancher has also an Agent part that manages the life cycle of containers.

If docker-machine creates a machine successfully, some events are exchanged between the docker-machine and the microservice. A bootstrap event is created and a docker-machine configcommand is executed to get the details needed to connect to the machine’s Docker daemon.

If everything run without problems, the service fires up a Rancher Agent on the machine via docker

run rancher/agent …

Rancher Agents open a WebSocket connection to the server in order to establish a 2-way communication. The Rancher Agent manage its containers and reports every change using the Docker API.

During this tutorial, we are going to use an EC2 machine and this is how a different view of the layers of our Rancher installation:

RancherOS Architecture

RancherOS

RancherOS is a small distribution released by Rancher team. It is an easy way to run containers at scale in production and includes only the services needed to run Docker.

It only includes the latest version of Docker and removes any unneeded library that a “normal” Linux distribution could have.

In RancherOS, everything is a container, the traditional init system is replaced so that Docker run directly on the Kernel.

A special component in this system is called User Docker which is the daemon that allow a user (a non-system user) runs its containers.

Now you can go to your <host_ip>:8080 and add a Linux host with a supported version of Docker:

Adding A Rancher Host

We are not going to use the public IP address but the private (eth0) one.

Adding A Rancher Host

Let’s add a custom host.

A command is given to run on any reachable host in order to let it join the server.At this step, I already created an EC2 machines (with RancherOS as an operating system) and I am going to use it and run this command:

We can also inspect other services and hosts configurations in the same way.

Cattle: The Rancher Container Orchestrator

What we started below is Rancher powered by its own orchestration tool called Cattle. Rancher offers the possibility to use other orchestration tools like Kubernetes, Docker Swarm or Mesos.

Cattle is a container orchestration and scheduling framework, in its beginning, it was designed as an extension to Docker Swarm but since Docker Swarm continues to develop, Cattle and Swarm started to diverge. Cattle is used extensively by Rancher itself to orchestrate infrastructure services as well as setting up, managing, and upgrading Swarm, Kubernetes, and Mesos clusters.

Cattle application deployments are organized into stacks which can be used to User or Infrastructure stacks. A CattleStack is a collection of Services and the latter is primarily a Docker image with its networking, scalability, storage, health checks, service discovery links, environment and all of the other configurations.

A CattleService could be a load balancer or an external service. A Stack can be launched using a docker-compose.yml or rancher-compose.yml file or just start containers like we did for the Wordpress stack.

In addition to this, you can start several applications using an application catalog. More than 50 different apps are available in the app catalog.

An application is defined by a docker-compose and a rancher-compose file and can be deployed easily with the default configurations.

Let’s take the example of Portainer:

Portainer is a lightweight management UI which allows you to easily manage your Docker host or Swarm cluster.Portainer is meant to be as simple to deploy as it is to use. It consists of a single container that can run on any Docker engine (Docker for Linux and Docker for Windows are supported).Portainer allows you to manage your Docker containers, images, volumes, networks and more ! It is compatible with the standalone Docker engine and with Docker Swarm.

Rancher offers the possibility to start infrastructure Stacks. If you go to Stacks->Infrastructure, you can see a catalog of tools like Bind9, Portainer, Rancher vxlan ..etc

Infrastructure Catalog

Scaling Wordpress Using Rancher

Now we want to scale our Wordpress frontal app in order to handle more traffic. In this case, you should click Stack->User then the name of the Stack (it should be the default one if you followed this tutorial as it is). Now click on Wordpress and scale your app to 3 containers:

At this step, you should see how Wordpress won’t scale the right way.

This is normal since all of our Wordpress containers are mapped to the same port 80 (that can handle only one container).

In order to scale Wordpress the right way, we should tell Rancher to create a load balancer service with auto-discovery and let Rancher choose the Wordpress container port automatically.

Connect Deeper

Painless Docker is a practical guide to master Docker and its ecosystem based on real-world examples.

Painless Docker tends to be a complete and detailed guide to create, deploy, optimize, secure, trace, debug, log, orchestrate & monitor Docker and Docker clusters. Through this book, you will learn how to use Docker in development and production environments and the DevOps pipeline between them in order to build modern microservices applications.

If you resonated with this article, please subscribe to DevOpsLinks : An Online Community Of Diverse & Passionate DevOps, SysAdmins & Developers From All Over The World.