Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Running Containers In a Virtual Machine

DZone 's Guide to

Running Containers In a Virtual Machine

Containers or VMs? Containers or VMs? Wait, why not both?

· Cloud Zone ·
Free Resource

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

Conclusion

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:

SQLSaturday Indianapolis Precon, Friday August 16th, 2019. Click here now to register.
SQLSaturday Oslo Precon, Friday August 30th, 2019. Click here to register.

Topics:
cloud ,virtual machine ,containers ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}