Running Containers In a Virtual Machine

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.

4 thoughts on “Running Containers In a Virtual Machine

  • walkerjian

    It is possible to run docker toolbox, and use the default install of virtual box as the virtualisation technology. I do this on an old Mac that I (unreasonably) like. I have also recently pulled a hyper-v stack from a windows 10 pro box I use as ‘big iron” due to constant update issues leaving the machine in a grossly unpredictable state. I installed docker toolbox on that too. You do miss out on being able to exploit the GPU, but win big time on versatility and predictability. I may be able to recompile the open source version of virtualbox so that the paid for by a sponsor nobbling of gpu passthrough is re-enabled. Maybe. Windows is a nightmare of broken and unpredictable ‘updates’ that is impossible to use for anything other than games. One thing – you can specify different virtualisation ‘engines’ than virtual box, maybe parallels or VMWare. Another thing – they are not infallible – I (fairly) recently had a docker toolbox install of tensorflow fail on a virtual machine due to the ‘version’ I pulled having a dependency on AVX compiled in that wasn’t there before. You really do need to pay attention to versions in the docker files and watch out for sneaky recompiles that break things sneakily… How to sabotage the entire open source stack in plain view, and apparently with the very best off intentions, in other words…

Please let me know what you think about this article or any questions:

This site uses Akismet to reduce spam. Learn how your comment data is processed.