Docker as a Service in vRA/vCAC part 2 – InstallPullandRun

So you want to offer your developers an Infrastructure as a service (IaaS) that is beyond just traditional Physical, virtual or cloud servers right? Well look no further, vRealize Automation can quickly and easily be extended to accommodate containers as an IaaS offering . In this guide I will show you how you can offer containers as a service through the vRA portal while still maintaining all the rich automation, reclamation, policy and governance that vRA is famous for. Add in NSX and you can also provision load balancers and networks for your containers! So what are you waiting for? Let’s get going!

Watch a short video of this integration.

Docker As a Service Part 1

NOTE: in part 1 we used the Linux Guest agent. While you can build on that blueprint with this guide, it is not required. This guide will also install and start the docker service so the guest agent is not needed.

media_1424606758507.png

Docker as a Service vRA/vCAC Extension v.1.0

Revisons: None

Pre-Reqs you will need in place for this solution:

  • vCAC 6.0, 6.1 or vRA 6.2 installed and configured (This will probably work with vCAC 5.2 but I have not tested)
  • vRA/vCAC configure to run vCO workflows at machine states. See my guide here.
  • RHEL or CENTOS 6.6 or higher blueprint setup to provision from the vRA or vCAC portal.
  • Provisioned VM’s need to have access to the internet to pull repository packages and docker images.
  • An NFS server with a mountable script directory available for you to run scripts and install software from. See this guide here.
  • A quite place to work for a few hours where you will not be interrupted.

Bonus:

  • If you need the docker images to download faster or your VM’s don’t have access to the internet, you may consider a local Docker registry. Follow my guide here. (NOTE you will need to modify the Docker scripts in this guide to work with a local docker registry)

Power on your Linux template and login as root or sudo to root and create directory on the root file system named repo. This is where you will mount your NFS share to.

media_1424607189384.png

Next, create a file named repomount.sh using the vi editor with the following content and save it.

media_1424607252731.png
mount -t nfs $1:$2 /repo &>/repomount.log

Make the repomount.sh executable by typing the following then pressing enter

media_1424607453787.png
chmod u+x repomount.sh

Now shutdown your template. Remember, if you are using Linked clones you will also need to take a new snapshot in vCenter Client and then run an inventory scan in vCAC and update the blueprint to point to the new snapshot.

 

Now let’s create the script that we will run to install Docker. Pull the Docker image and start the container. Using the vi editor create the script dockerpullandrun.sh

media_1424607750484.png

Press the i key to change to insert mode and enter the following lines then press escape and then Hold Shift and press ZZ to save it.

media_1424607787018.png
yum -y install epel-release 
yum -y install docker-io
service docker start >/dockerstarted.log 2>&1
chkconfig docker on 
sleep 30
$1 >/dockerpull.log 2>&1
$2 >/dockerrun.log 2>&1

Now make the script executable with the following.

media_1424610693642.png
chmod u+x dockerpullandrun.sh

The above script is first installing the Extras packages, then it installs docker, next it starts the docker service then adds it to start at boot. The next step is a sleep for 30 seconds to make sure docker is started properly. Then I pass the Docker run string and Docker pull string from the user input in vRA to pull and run the container.

Now we need to import the workflow package into your vCO instance. NOTE: if you have not already configured vRA and vCO together this guide will not work.

Download My Package here >>.org.vmtocloud.vravcac.dockerinstallpullandrun

The file is in ZIp format. Unzip the file first and then log into the vRO client and import the package like so.

media_1424609618873.jpg

This workflow uses the Guest Script Manager Package created by @cdecanini_ over at https://communities.vmware.com/docs/DOC-25474

Under the VMtocloud folder you should see a new workflow named DockerInstallPullandRun

media_1424609864174.png

Edit this workflow and go to the General tab. You will need to edit the vmUsername and vmPassword so the workflow can access the newly provisioned VM.

media_1424609953294.jpg

Now save and close the workflow

media_1424610034606.jpg

Now we need the workflow ID so we can create the Build Profile in vRA to call this workflow as part of the provisioning process. Copy the ID to the clipboard.

media_1424610156310.jpg

Now login to the vRA\vCAC portal and navigate to the Infrastructure tab, then Blueprints and build profiles and create the following build profile. Notice the DockerPull and DockerRun Prompt the user. Click OK to save the build profile.

media_1424610449741.jpg
docker.pullandrun.script /repo/dockerpullandrun.sh
DockerPull
DockerRun
ExternalWFStubs.MachineProvisioned This is the ID of the vCO workflow you copied to your clipboard. 
repo.path The path to your NFS share
repo.server The NFS server
VMware.VirtualCenter.OperatingSystem rhel6_64Guest

Now attach the Build profile to you RHEL/CENTOS 6.6 template and verify the properties are correct.

media_1424611032708.jpg

Now fire off a new request and provide the Docker Pull and Run commands you want. I provided an easy ones below.

media_1424611210547.png
docker pull vmtocloud/myblog
docker run -d -p 80:80 vmtocloud/myblog

After several minutes or up to 20 minutes depending on your network speed, the machine should finish provisioning.

media_1424611412457.png

Open a web browser to the new servers address and let the magic begin!

media_1424611467177.png

Some helpful troubleshooting tips. If the vRO workflow does not run this integration will not work. Check vRO and vRA for status. in vRO watch to see the workflow runs and monitor status.

media_1424611585833.png

Also watch the following screen in vRA/vCAC to check the status of the VM provisioning. The vRO workflow should run in Machine Provisioned stage

media_1424612221214.png

Enjoy, I will also post a modified version of this with a local docker registry soon.

Remember, sharing is caring ->Tweet about this on Twitter
Twitter
0Share on Facebook
Facebook
0Share on LinkedIn
Linkedin
Share on Google+
Google+
0Email this to someone
email

2 Replies to “Docker as a Service in vRA/vCAC part 2 – InstallPullandRun”

  1. Pingback: vRealize your containers with VMware | VMtoCloud.com

  2. Pingback: Containers for the vSphere Admin | VMtoCloud.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.