This week has been fairly mellow, so I decided to play with Rancher. What is Rancher?
Rancher is an open source software platform that enables organizations to run containers in >production. With Rancher, organizations no longer have to build a container services platform >from scratch using a distinct set of open source technologies. Rancher supplies the entire >software stack needed to manage containers in production.
Why Rancher may be useful…
Once you get past the “how do I create, access and tear down” docker containers, you need to start thinking of a way to keep things in order when going to production - or even on staging and testing environments. This is where Rancher comes in:
- Infrastructure Orchestration
- Container Orchestration & Scheduling
- Application Catalog
- Enterprise-Grade Control
Since I work on my Macbook Pro every single freaking day, I wanted to ensure I can play with containers both on Windows and Linux. To give you a visual of what my current setup looks like, take a look at the image below.
[image credit @stefscherer]
Setup the Windows Host
This is the box that we will use to also install Docker and run some containers. I provision it using Vagrant which allows me to tear it down and build easily!
Here is what the Vagrantfile looks like
The base Windows box is provisioned along with preinstalled packages including Chocolatey, Git, Atom (my favaorite editor - I wrote a theme, you can view it here )
Provision The Windows Host
Place the Vagrantfile within a directory of your choice and run
vagrant up, yes that is all it takes. Machine should be provisioned with all of the preinstalled software we outlined on the Vagrantfile.
Setup Rancher server
To quickly get started, I used a script from the 10-acre-ranch github repo and executed the following:
The script creates three VMs using docker-machine-driver-xhyve
As you can see form the image above, we can also find the IP address of the Rancher Server so that we can access it via the browser. In this case it is
http://192.168.64.2:8080/. We use port 8080 because that is the port the container is running under. If you wanted to check you can execute
docker ps after setting your terminal session as follows
eval $(docker-machine env rs)
Now we need to do the following to finish setting up Rancher:
- [ ] Setup Rancher Access Control (we will use Github OAuth)
- [ ] Setup “Windowws Test Lab” Environment via Rancher UI
- [ ] Add Windows Host via Rancher UI
Setup Access Control Using Github Authentication
You can setup Rancher to authenticate users with existing accounts, this can be Active Directory even Azure AD - for some other Identity Management system. For this scenario, I will use Github OAuth.
On your Github account
- Go to Admin > Access Control
- Select > Github
- Go To Github site > OAuth Applications and add Rancher, it should look like this
If all goes well, you are now using Github authentication for your Rancher instance and it will look like this
Setup Windows Test Lab Rancher Environment
Via the Rancher UI on top left, simply select Manage Environments. Add a new one, select Windows as shown below.
Add Windows Host Via Rancher UI
First we want to make sure the Windows Server is up and running.
Next follow these steps:
- [ ] Ensure you have selected the Windows Test Lab Environment on Rancher UI
- [ ] Go to Infrastructure > Hosts > Add Host
- [ ] You will notice you can setup either a Windows or Linux Host, copy and paste the two commands onto a PowerShell Window on the Windows machine we created earlier.
The Rancher UI allows you to copy the PowerShell commands you need to run on the Windows Host as shown below.
The PowerShell installs the Rancher Agent on the Windows Host and starts it. This is actually a Windows Service.
Deploy an Image from Docker Hub Registry
For this example, I want show you how you can deploy an IIS website. Our first step is to create a Dockerfile that looks like the following:
Then build the image by running
docker build -t sharepointoscar/mywebsite:test . This will build the IIS custom image prepopulated with my own website content as shown on the Dockerfile.
Next we execute
docker push sharepointoscar/mywebsite:test to the registry.
Deploy The Custom IIS Image as a Service
Now that we have our IIS custom image prepopulated with our static website content, we will create a Service and expose the port to access it.
First, we want to create a Stack on the Rancher UI doing the following:
- Go to Stacks > All
- Click on Add Stack
- Give it a Name and Description that makes sense to you. I used tags to distinguish environments.
Now we add a Service. Fill in as follows:
- Name set to MyWebsite
- Description something meaningful mine is Mywebsite running on IIS Docker Container
- Under Select an Image, I typed my image which I previously uploaded to the Docker Hub Registry. I type sharepointoscar/mywebsite:test
- Under Port Map, I know that I exposed port 8000, so I entered 8000 on both Public Host and Private Container Port
- Click on Create and shortly the service will be up!
It should look like this
When you click on it, you get more details on the setup including the container IP address to access it via the browser as shown below
In addition, Rancher has pulled the
sharepointoscar/mywebsite:test image and ran it on the Windows Host as shown below
If all goes well, you should be able to access your site as shown below
Well, this does it! I hope this was helpful and drop me a line if you have any questions.