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.
Pre-Reqs:
- 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
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/login-to-a-machine-running-docker-or-kubectl.png)
Clone my Git Repo locally
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/clone-my-git-repo-locally.png)
git clone https://github.com/vmtocloud/makevmcontainer.git
Change to the makevmcontainer directory
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/change-to-the-makevmcontainer-directory.png)
cd makevmcontainer
use vi to edit the makevm.ps1 file
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/use-vi-to-edit-the-makevmps1-file-.png)
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’
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/edit-the-variables-section-with-information-about-your-vcenter-environment.png)
When you are done editing hit escape key and hold shift and type zz to save and exit
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/when-you-are-done-editing-hit-escape-key-and-hold-shif-and-type-zz-to-save-and-exit.png)
Now let’s build the container
Type
docker build -t makevm .
and press enter
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/now-let-s-build-the-container-.png)
If all went well you should see your new conatiner image
Type
docker ps
and press enter
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/if-all-went-well-you-should-see-your-new-conatiner-image-.png)
Now just run the container and watch the magic begin!
Type
docker run makevm
and press enter
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/now-just-run-the-container-and-watch-the-magic-begin-.png)
Notice in vCenter the new VM provisioning
![](https://www.vmtocloud.com/wp-content/uploads/2020/09/notice-in-vcenter-the-new-vm-provisioning.png)
Enjoy, my next step is to get this to work in docker compose, I have some ideas but curious what you all think.