1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Installing and managing Docker by Using the Rancher API’s

Today I am going to to demonstrate how to use Rancher and especially the Rancher API’s to manage a Docker environment. As discussed in the past, there are several options to use for managing your Docker environment. in my previous post I demonstrated how to use Shipyard to manage your Docker environment, and today I will be working with Rancher and the Ranchers API’s. Rancher is a full fledged Docker Management suit, weather you use Docker Swarm, Kubernetes, Mesos, or a cloud provider like AWS, Azure, GCP, etc…, Rancher is here to help you. All of the above plus more can be managed straight from the Rancher Web-UI, the Rancher Web-UI is extremely powerful, it can also manage your Docker Registry, Docker Stacks, Docker Storage, Docker Compose. Rancher also created a powerful alternative to docker-compose called rancher-compose, another plus is the Rancher Catalog stack, you can install any application stack available in the Catalog with (almost) one click, or even create your own catalog stack. Having said that, one of the key points I like about Rancher is the API’s. The Rancher API (v1 or v2(beta)) can be demonstrated/tested directly from within the Web-UI, and almost everything that works in the Web-UI can be accessed with the API. Enough talk, let’s jump right in.

Installing Rancher – Getting Rancher to Work

To install the Rancher just run the below, this will expose port 8080 for managing with the Web-UI.
docker run -d --restart=unless-stopped -p 8080:8080 rancher/server
After connecting to the Rancher Web-UI for the first time, you will need to click on INFRASTRUCTURE > HOSTS > Add Host. Below is a screen capture of Adding a Host To Rancher Next, complete all the fields, this will generate something like the below, run that on your Server-Client/Agent.
docker run -e CATTLE_AGENT_IP=""  -d --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.1
Note: Its possible you will need to login to the Rancher container and add your servers name, ip (and possibly your porxy name and ip), then reboot that container and run the above again. Below is the error you might get.
docker run ...
INFO: Running Agent Registration Process, CATTLE_URL=
INFO: Attempting to connect to:
ERROR: is not accessible
ERROR: is not accessible
ERROR: is not accessible
If you get the error above, just follow the solution below – add the Rancher Server host/ip to the rancher agent host, like the below.
docker exec -it `docker ps -a|grep agent|awk '{print  $1}'` /bin/bash
root@e913b3999555:/# echo " rancher" >>/etc/hosts

# Agent Initialize should now continue in the other window...
INFO: is accessible
INFO: Inspecting host capabilities
INFO: Boot2Docker: false
INFO: Host writable: true
[..] snip
INFO: Launched Rancher Agent: 9a5aa79e28a4b362857adbf16bf3727656bc5a5b5da9784c0ac24bcb70e0bd32
After issuing the above commend, Rancher will configure a number of containers used for internal services, for example ipSec, etc… Once the setup is complete, go ahead and start playing, adding containers, hosts, working in the UI, it is a very simple and powerful UI.

Configuring and working with the Rancher API

While using the Web-UI is great, at some point you might find your self looking to integrate or automate with other parts of the system, for that reason, Rancher created the CLI or API. As said, Rancher has a very powerful API, but in order to use it, we need to prepare the system for that. In the next steps, I will show you how to prepare the system to be able to use the Rancher APY’s.

Setting the system for local authentication

By the default the system is set to use Git under Access Control. Lets change that to use Local Authentication. alternatively you can use AD or LDAP. To change the system to use Local Authentication, just follow the below steps.
  1. Click on ADMIN > Access Control
  2. Click on the Local Authentication box, then click Apply
Tip: Once you change the system to use Local Authentication, you can not rollback to something else.

Generating API keys

Next lets generate API keys, the API keys will be used for all system communications. Click on API > Keys. Now, click Add Account API Key. Optional, give the API key a name and Description. Note: In my case I used for Name: elis-api and for Description: Elis API Key, used for remote administration Next, Click Create. Now, you should get a new API Secret and Access Key. Make note of the Secret, as its un-retrevable after you leave this screen. Rancher API account after creation In the next part, I will be showing you how to Manage Docker With Rancher APIs, By Using Python, Curl, etc… What was your experience Managing Docker? Are you using Rancher or something else? please let me know in the comments below.
5 1 vote
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x
%d bloggers like this: