Managing Docker With Rancher APIs By Using Python Or Curl – Part 1

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

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.

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.

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.

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.


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.

Leave a Reply

avatar
  Subscribe  
Notify of