Earlier this week I wanted to show someone a copy of Rancherā†— running but I realized that I didnā€™t have a local lab configured. I managed to quickly launch a few machines in Digital Oceanā†— meaning I could do the demo.

Rancher is described as beingĀ ā€¦

From the ground up, Rancher was designed to solve all of the critical challenges necessary to run all of your applications in containers. Rancher provides a full set of infrastructure services for containers, including networking, storage services, host management, load balancing and more. All of these services work across any infrastructure, and make it simple to reliably deploy and manage applications.

As I am running the Docker for Mac Beta I got to thinking if I could use that to launch Rancher and then using Docker machine to launch a few hosts running RancherOSā†— to act as hosts.

Letā€™s do the easy bit, launching Rancher is incredibly easy. I just ran the following command;

Launching a local Rancher cluster 1/9
docker run -d ā€” restart=always -p 8080:8080 rancher/server:latest

It takes a minute for Rancher to download and start. You can check the progress by running docker logs container_name against the containers name, you can find the containers name by running the docker ps command.

rancher01

This started the Rancher server on port 8080 on my Mac, at the moment there is a problem which causes the UI to error when running in Safari so I opened it with FireFox by running;

Launching a local Rancher cluster 2/9
open -a FireFox http://localhost:8080

You will notice that we are accessing Rancher using localhost, when it comes to launching the host VMs they will not be able to access that address so lets grab the IP address of our local machine;

Launching a local Rancher cluster 3/9
ipconfig getifaddr en1

For me, this was 10.0.1.15. Next up lets goto FireFox, if everything went as planned you should see a screen asking you to add a host. While we havenā€™t got our host VMs launched we will need to configure Rancher to listen on our local machines IP address. To do this click on ā€œAdd Hostā€, when you do this you will be able to a page which asks you to confirm the ā€œHost Registration URLā€.

This is the URL which our host machines will use to call back to the Rancher server, to update it click on the ā€œSomething elseā€ radio button and your IP address and port;

rancher02

Once you have updated the IP address click on ā€œSaveā€, you will then be taken a screen where you can add your hosts. Ignore steps one through to four, step five should give you the command you need to run on your host machines to download the Rancher client agent and register itself with your server. For me this command wasĀ ā€¦.

Launching a local Rancher cluster 4/9
sudo docker run -d ā€” privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.0.1 http://10.0.1.15:8080/v1/scripts/2925437AFC94D6994999:1465743600000:C8O5m4OXR0giBvn3DonFFvow

Once you have made a note of the command, click on ā€œCloseā€ and go back to your terminal to launch a few host VMs. Here we will be using Docker Machine to launch two VMs running RancherOS.

RancherOS is a tiny Linux distro that runs the entire OS as Docker containers.

To do this run the following two commands;

Launching a local Rancher cluster 5/9
docker-machine create -d virtualbox ā€” virtualbox-boot2docker-url https://releases.rancher.com/os/latest/rancheros.iso rancher01
docker-machine create -d virtualbox ā€” virtualbox-boot2docker-url https://releases.rancher.com/os/latest/rancheros.iso rancher02

You can check that your machines are OK by running docker-machine ls, you should see something like;

rancher03

Now we have our two host machines up and running we just need to launch the agent container. To do this run the following command, making sure to replace the end part with the command from step five on your own Rancher installation;

Launching a local Rancher cluster 6/9
docker-machine ssh rancher01 docker run -d ā€” privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.0.1 http://10.0.1.15:8080/v1/scripts/2925437AFC94D6994999:1465743600000:C8O5m4OXR0giBvn3DonFFvow

and for the second host VM;

Launching a local Rancher cluster 7/9
docker-machine ssh rancher02 docker run -d ā€” privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.0.1 http://10.0.1.15:8080/v1/scripts/2925437AFC94D6994999:1465743600000:C8O5m4OXR0giBvn3DonFFvow

once you have ran the commands, it will take a minute or two for the agents to register themselves with your server. Once the hosts have registered themselves you should see something like the following;

rancher04

You can now start to launch services from the catalog etc;

rancher05

To teardown the cluster run the following command, replacing the ā€œamazing_brattainā€ with the name of your container, to stop and remove the container running the Rancher Server;

Launching a local Rancher cluster 8/9
docker stop amazing_brattain && docker rm amazing_brattain

and to remove the two hosts run;

Launching a local Rancher cluster 9/9
docker-machine rm rancher01 rancher02

So thats how you can quickly launch a local Rancher cluster using the Docker for Mac beta and Docker Machine.