How to use Docker and Kubernetes to provision vSphere VM’s

Sometimes you feel like a container….

Sometimes you don’t….

So you are building that next killer app or just starting to migrate your apps to containers but you realized you’re just gonna need to provision a VM to complete the build process. Well you are in the right place. In this guide I will show you how to provision vSphere VM’s with docker commands. This also works on Kubernetes.


  • A machine running the latest Docker. I prefer Photon OS 3
  • A working VM template configured in vCenter, I used CentOS 7
  • A user account on vCenter with permission to create new VM’s from template
  • Network connectivity from the Docker machine to the above vCenter Server
  • A quiet place where you will not be interrupted see my guide here

Login to a machine running docker

Clone my Git Repo locally

git clone

Change to the makevmcontainer directory

cd makevmcontainer

use vi to edit the makevm.ps1 file

vi makevm.ps1

Edit the variables section with information about your vCenter environment

Note: You may need to get this information from your vSphere administrator, keep the password in single quote for example ‘mypassword’

When you are done editing hit escape key and hold shift and type zz to save and exit

Now let’s build the container


docker build -t makevm .

and press enter

If all went well you should see your new conatiner image


docker ps

and press enter

Now just run the container and watch the magic begin!


docker run makevm

and press enter

Notice in vCenter the new VM provisioning

Enjoy, my next step is to get this to work in docker compose, I have some ideas but curious what you all think.

Remember sharing is caring!