Running Containers In a Virtual Machine
Containers or VMs? Containers or VMs? Wait, why not both?
Join the DZone community and get the full member experience.Join For Free
The more you work with containers, the more you just want to work with containers. However, there are still reasons to have a virtual machine for some types of workloads. So, what if you want to work with containers inside a virtual machine. Is that possible?
Yes, and shockingly easily.
Enable Virtualization In Virtualization
I knew from conversations I've had previously that running Docker inside a virtual machine was possible. I just didn't know the details. So, with a complete lack of knowledge, I did the most expedient thing possible: I installed Docker in a VM and started it up.
Now, let's talk about my setup for a moment. My laptop is running HyperV as my hypervisor. You have to have some type of hypervisor for Docker to work. I'm running a Windows Server 2019 virtual machine. That's the extent of the set up.
After installing Docker, you have to "reboot" the machine, so my VM restarted. I received an error from Docker that virtualization wasn't enabled on the machine.
Earlier, I had mentioned I was doing this setup. I received a response from Allan Hirt that I would need to do one thing to make it all work. He even provided me with a link: Enable Nested Virtualization.
Running the one command:
Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true
It all worked. It was shockingly easy. From there it was back to basic Docker commands and I could fully control virtualization inside my virtual machine
I was a little surprised at how easy this was, but the rewards for the setup were immediate. I had a PostgreSQL database up and running in no time so I could some automation testing for an upcoming precon (details below). Containers really are changing how we do what we do.
Want to see how I'm automating database deployments to PostgreSQL and containers? Here are a couple of opportunities:
Published at DZone with permission of Grant Fritchey, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.