How to use docker-machine in conjunction with the vSphere driver

This article was originally posted on the VMware Cloud Native corporate blog. I am re-posting here for the convenience of the readers of my personal blog.

As many of you know docker-machine is the client side tool that allows an individual on his/ her own workstation to fire up docker hosts either local or remote.

Docker-machine supports a variety of “drivers” to accomplish this. Some of these drivers deploy locally (e.g. Virtualbox, VMware Fusion), some of them deploy inside the data center (e.g. OpenStack, VMware vSphere) and others can deploy in public clouds (e.g. AWS, VMware vCloud Air).

As I was experimenting with the vSphere driver for some tests I was doing with Docker Swarm, I found that the number of options available on the vSphere driver and the flexibility it provides, could make its usage challenging without proper examples to kick off the scripting.

For this reason, I am sharing some of the scripts I have used for my experiments with the ultimate goal of providing solid practical examples of how to use those vSphere parameters.

For your convenience, I am also attaching the variable configuration examples in this post.

This is how you’d configure the variables or corresponding options if you were to deploy to a vCenter server:

 1VSPHERE_VCENTER=192.168.1.12                                   # vCenter IP/FQDN
 2
 3VSPHERE_USERNAME=’administrator@vsphere.local’                 # vCenter user
 4
 5VSPHERE_PASSWORD=’***********’                                 # vCenter user password
 6
 7VSPHERE_NETWORK=’VM Network’                                   # PortGroup
 8
 9VSPHERE_DATASTORE=’datastore1′                                 # Datastore
10
11VSPHERE_DATACENTER=’Home’                                      # Datacenter name
12
13VSPHERE_HOSTSYSTEM=’Cluster1/*’                                # cluster name
14
15#VSPHERE_POOL=’/Home/host/Cluster1/Resources/SwarmTeam13′      # *optional* Resource Pool name

This is how you’d configure the variables or corresponding options if you were to deploy to a standalone ESXi host:

 1VSPHERE_VCENTER=192.168.209.11                                 # ESXi IP/FQDN
 2
 3VSPHERE_USERNAME=’root’                                        # ESXi user
 4
 5VSPHERE_PASSWORD=’***********‘                                 # ESXi user password
 6
 7VSPHERE_NETWORK=’VM Network’                                   # PortGroup
 8
 9VSPHERE_DATASTORE=’datastore1′                                 # Datastore
10
11#VSPHERE_POOL=’/*/host/*/Resources/SwarmTeam9′                 # *optional* Resource Pool 

In particular, the syntax to use for the VSPHERE_POOL variable (or corresponding options) requires a bit of attention.

Let’s say, for example, that you want to deploy a 5-node Swarm cluster in a vCenter Resource Pool called “SwarmTeam13”, inside a cluster called “Cluster1”, in a data center called “Home”.

To do so, you will use the first syntax above inside the swarmcluster_consul.sh script and then you will run it on your workstation using the following parameters:

1> ./swarmcluster_consul.sh 5 vmwarevsphere vcenter_

Note: the VSPHERE_POOL variable has to be set if you want to deploy inside a Resource Pool (and not in the root of the cluster) so you need to remove the comment preceding the variable.

This is what you will see in the vCenter UI once the script has completed:

You can set the proper environmental variables to access the Swarm cluster by running the following command at the prompt:

1> eval $(docker-machine env --swarm swarm-node1-master)

If you want to play with the scripts and deploy / destroy an entire multi-node Swarm cluster on vSphere, just grab them here.

Enjoy!

Massimo.