Rancher: New containers for the (server) farm – quick and easy

There are several ways to start new stacks (=applications consisting of several containers) with Rancher. While it is possible to start the individual containers via the command line as with Docker or via docker-compose (see part 2), there are additional, simpler options with Rancher. In the web interface, it is possible to create each container individually – similar to an interactive compilation of a docker-compose file. The more elegant and simpler option is to use rancher-compose.

A docker-compose.yml is used and an additional rancher-compose.yml is created. The extension contains the scaling, configuration of the load balancer and the health checks. If the additional Rancher tools are not required, the extension can also be omitted. However, it should be noted that Rancher has only switched to the same syntax version as docker-compose (version 2) since version 1.2 (released in December 2016), which is why there were previously differences in the structure of the compose files. As a result, not all docker-compose files were automatically compatible with Rancher. Since Rancher version 1.2, however, this is no longer the case and the corresponding docker-compose files can optionally be supplemented by rancher-compose files.
The extension contains the scaling, configuration of the load balancer and the health checks. If the additional Rancher tools are not required, the extension can also be omitted. However, it should be noted that the syntax of docker-compose is now usually used in version 2, while Rancher only understands version 1. This means that not all docker-compose files are automatically compatible with Rancher. There are three ways to use rancher-compose: running it via the command line on the Rancher server in the directory in which the two yml files are located, uploading the yml files in the web interface or copying or writing the yml files directly in the web interface. In the web interface, it is also possible to export the current configuration from any running stack as docker-compose.yml and rancher-compose.yml. To revisit the example from part 2 with a WordPress blog, the example is shown below in a Rancher-Compose version. A load balancer has been added next to the database. This is actually superfluous for a single WordPress container, but the number of WordPress containers can be scaled up at any time and the load is distributed across all existing containers via the load balancer. The WordPress blog itself is then accessible at the address of the server with the load balancer, even if the WordPress container itself is running on a different host.docker-compose.yml:

version: '2'
services:
  WordPress:
    image: wordpress:latest
    environment:
      WORDPRESS_DB_HOST: database:3306
      WORDPRESS_DB_PASSWORD: wordpress
    links:
    - database:database
  Loadbalancer:
    image: rancher/lb-service-haproxy:v0.4.6
    ports:
    - 80:80/tcp
  database:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_PASSWORD: wordpress
      MYSQL_USER: wordpress
      MYSQL_DATABASE: wordpress

rancher-compose.yml:

version: '2'
services:
  WordPress:
    scale: 2
    start_on_create: true
  Loadbalancer:
    scale: 1
    start_on_create: true
    lb_config:
      certs: []
      port_rules:
      - hostname: ''
        path: ''
        priority: 1
        protocol: http
        service: WordPress
        source_port: 80
        target_port: 80
    health_check:
      response_timeout: 2000
      healthy_threshold: 2
      port: 42
      unhealthy_threshold: 3
      interval: 2000
  database:
    scale: 1
    start_on_create: true

In this example, there are two WordPress containers to which the load balancer distributes the requests.
In addition, a catalog with preconfigured stacks can be used in the Rancher interface. For these stacks, you can define which parameters still need to be specified and everything else is already preconfigured. There is a clear catalog of the Rancher community for certain stacks that are frequently used or can also be used very well for testing Rancher.

In addition to the community catalog, you can also create and integrate your own catalog via GitHub. This can also be used to create a catalog of preconfigured stacks in an internal network that are frequently used or where the majority of the configuration is not changed. In most cases, this makes it even easier to start an entire program stack than via rancher-compose and does not require any prior knowledge of which configuration parameters are required for operation.

This is part 5 of a series of blog posts on the topic of Docker/Rancher.

Part 1 provides an overview of Docker and container environments

Part 2 explains the functions of a Docker registry and docker-compose

Part 3 introduces Docker Swarm with a Docker environment distributed across multiple hosts

Part 4 shows Rancher as an orchestration tool for Docker (and other container environments)

The following two tabs change content below.

ATIX-Crew

Der ATIX-Crew besteht aus Leuten, die in unterschiedlichen Bereichen tätig sind: Consulting, Development/Engineering, Support, Vertrieb und Marketing.

Latest posts by ATIX-Crew (see all)