I’ve been catching up on my massive RSS backlog during my vacation (that is the result of frequent traveling and having a little girl at home) and stumbled upon Massimo great post on Docker: Docker on vCHS (with 2 API Calls).

Massimo explains in great detail how to get a container running on Docker in vCHS, with several examples of doing it manually, through the web UI and with API calls; I will admit I just played around with Docker a couple of times, not because it’s not worth attention, but because a day is made of 24 hours and some of them are meant for sleeping ;-)

Anyway, this tweet from Jake Robinson made me realize that with Vagrant and our VMware providers, Docker support is literally a vagrant up away ;-)

So before making a post on this, I wanted to test it out myself (dogfooding is key), to do so I tested the same container that Massimo used in his post (tutum/wordpress) and leveraged the docker provisioner that is included in Vagrant 1.6+.

Let’s look at the Vagrantfile syntax (vagrant-vcenter version):

As you can see, in the upper part we define the nodes we want to have (this relates to the number of docker hosts we want to deploy), the box is a very simple Ubuntu 14.04 LTS box coming from our Vagrant Cloud account.

The second part is devoted to the vagrant-vcenter provider configuration, nothing special here, just make sure to use linked_clones to make the provisioning phase faster.

The third part is the most interesting for our Docker trials, the do loop cycles through the nodes hash and set up the box and hostname, then delves into the docker provisioning, first of all, Vagrant pulls Docker from the internet and installs it in the box it just deployed, and then goes through deploying and starting the containers specified in the docker nested loop, in our case it pulls tutum/wordpress and runs it with the /run.sh command and maps the port 80 from the container to the hosting VM on the same port.

Once we issue a vagrant up --provider=vcenter, Vagrant will pull the gosddc/trusty64 box from Vagrant Cloud, upload it to the datastore specified, and create a new VM, that will be provisioned with Docker and the container specified, and will ensure that the container is running before exiting.

A vagrant ssh will then connect us to the Docker host and show us the IP that the machine has, we can also run a docker ps to ensure that the container is actually running.

docker run screenshot

The container is up and running! we can now connect to the webpage and see the familiar Wordpress install page ;-).

wordpress running in a container

Obviously, this can be used with our vagrant-vcloud provider too, both on vCloud Hybrid Service (vCHS) or on every (well-configured) vCloud Director powered Cloud!

Enjoy Docking!

Fabio Rapposelli Picture

About the author...

  dockervirtualizationcloud

Comments