Using Rancher to manage your Docker containers

It's not new that Docker containers are being largely used to deploy applications in small, medium and large companies. There's no doubt that this is the new way to deploy software. Given all the benefits, doesn't make sense to waste time configuring servers, debugging some error in production related to package versions, etc.

But, as the number of containers tends to increase more and more in many companies, we need to start thinking about orchestration and how to manage all the containers and hosts.

One tool that I really like to use is Rancher. It's basically a web interface (but can be way more powerful than that) that gives you power to deploy your containers wherever you want. The interface is pretty intuitive and it's unbelievably easy to start using. To run Rancher, you just need to run $ sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server. Yes, the rancher server is a also a docker container and there is no need to configure nothing more to start deploying your containers. More than just a web interface, Rancher is so powerful that it can configure an entire Kubernetes/Mesos cluster for you…all you have to do is to give Rancher the hosts that will be used and every needed component to run the chosen orchestration tool will be automatically installed.

The way Rancher communicates with the hosts is by having rancher agents running on each host. You only have to run a rancher agent container, really simple. Rancher also provides integration with some cloud providers like Amazon AWS, Azure, Digital Ocean, etc. So, adding hosts can be even easier, you just have to provide, for example, your Access key/Secret key (if you choose AWS) and Rancher will take care of provisioning the Virtual Machines.

After adding your host, you have access to some metrics (cpu usage, memory usage, IP address…) and you can add containers to your host.

You can easily define the port maps, policies, link one container to another, add environment variables, you can define memory and cpu limits, secrets, etc.

Creating a container is as simple as filling the forms above and clicking 'Create'. The container will start and you will be able to see metrics related to this container.

Metrics for a redis container. You can also restart the container, stop, delete, view the logs, executing shell commands…everything by the user interface, without the need to login into the host.

Another great feature that I love to use is the possibility to upgrade a container image and, if something goes wrong, easily rollback. This can be done by defining stacks and services. A stack could be your Rails app, for example, and the services would be: nginx, mysql, redis, mongodb, etc. Once your service is deployed, you can click use the 'Upgrade Service' to modify any configuration and deploy. Rancher will stop the current container and deploy the new one. After deploying the new service, you can choose to rollback or to maintain the new version. In my opinion, this feature is extremely useful when you want avoid being offline for a long time. Of course it's not the only way to deal with this kind of requirement…Blue Green deployments are used to perform tasks like this, but using this Rancher's built-in feature is still useful and doesn't require any implementation.

If you need a Load Balancer, you can load a HAProxy instance (provided by Rancher) and link to your containers. Once you scale your containers up and down, the HAProxy's backend will be automatically updated to load balance traffic to the new containers.

If you need some reasons to convince your boss to use it, I would say:

  • Easy to install and maintain -> It's a docker container!
  • Integration with many Cloud Providers
  • Possibility to define environments (development, staging, production…)
  • You can integrate external services to Rancher via an API (you can define a CD pipeline by using Jenkins and Rancher, for example)
  • Want to use Mesos/Kubernetes/Swarm? No need to waste your time configuring the cluster, let Rancher do it for you
  • You can have a better vision of what's running on your hosts and easily interact with the containers without the need to login into every host
  • Possibility to use a powerful load balancer (HAProxy) and linking to your containers, having automatic updates as you scale up and down your services.
  • Great community.
  • Open-source, free to use.

I will prepare another post explaining how to deploy a Mesos/Kubernetes cluster using Rancher. I hope you try Rancher. :)

See you soon!