Hyper-V provides an excellent platform for both Windows and Linux guest operating systems. Hyper-V administrators may want to install a Linux guest operating system to serve as a Linux-based container host to run containers. The Linux virtual machine approach to running containers with Hyper-V is still the most stable and supported method for running containers with Hyper-V without a paid solution. Let’s look at Hyper-V based Linux containers in this article.
Table of Contents
- Windows vs Linux containers
- Create a new Hyper-V Linux Virtual Machine
- Change to make for Generation 2 Hyper-V Linux VM
- Beginning the installation of Ubuntu 22.04
- Hyper-V Containers Linux virtual machine FAQs
- Why load a Linux Virtual Machine for Hyper-V containers?
- Are Hyper-V containers free?
- Are there other ways to run Linux containers in Hyper-V?
- Wrapping up
Windows vs Linux containers
While you can run native Docker containers on your Hyper-V host, you must run Windows containers. It is because containers share the kernel of the host operating system. However, a few documented approaches to running Linux containers with Hyper-V isolation exist.
These methods for running free Hyper-V Linux containers include Windows Subsystem for Linux in Windows Server 2022 and Docker desktop (non-enterprise version). There is another way, using LinuxKit. Unfortunately, you have to choose whether to run Windows or Linux containers on your host, not both.
Running a Linux virtual machine is still the most straightforward free option for Hyper-V containers in production. So, let’s look at loading an Ubuntu 22.04 virtual machine in Hyper-V for running Linux containers in Hyper-V.
Create a new Hyper-V Linux Virtual Machine
First, we need to create the Hyper-V VM that will be the shell for the Ubuntu Server installation. Launch the New Virtual Machine Wizard. Click Next.
Specify a name for the new Linux virtual machine. Also, change the storage location if you want to configure a location different from the default.
Specify the Hyper-V Generation of the new Linux virtual machine.
Assign the configured memory for the new Linux virtual machine.
Configure networking for the new virtual machine. Here you will connect the Linux virtual machine to the Hyper-V virtual switch of your choosing.
Connect a virtual hard disk. If you are not connecting to an existing virtual hard disk, you can create one using the wizard. Here, we are creating a new 40 GB disk.
Select the installation image for installing your Linux virtual machine.
Finally, we are ready to complete the New Virtual Machine Wizard for creating our new Linux container host virtual machine for running Hyper-V containers.
Change to make for Generation 2 Hyper-V Linux VM
We need to make a change to ensure our Ubuntu Server will work on the Generation 2 Hyper-V virtual machine. Once you complete the creation of the Ubuntu Server virtual machine, navigate to the properties of your new VM. Select Security > Template > Microsoft UEFI Certificate Authority. If you do not make this change, your Ubuntu Server VM will not boot using the default Generation 2 settings.
Beginning the installation of Ubuntu 22.04
Next, we will follow the default workflow for installing Ubuntu Server 22.04 in our Hyper-V VM. Once we power on the VM, it will boot into the Ubuntu installer.
Choose your installation language.
Choose if you want to update the installer to the latest version.
Choose your keyboard configuration.
Choose your installation type.
Configure your network settings.
If you need to configure proxy settings, you can do that on the next screen.
Configure your storage settings.
Verify your storage configuration.
Confirm disk formatting and destruction of existing data.
Set up your local user and password for logging into your Ubuntu Server system.
Verify installing OpenSSH Server.
Specify any additional packages you want to install.
The Ubuntu Server installation begins.
The installation of Ubuntu Server 22.04 completes successfully. Select Reboot Now to reboot your Ubuntu Server installation.
Once rebooted, we can log in to our Ubuntu Server 22.04 installation.
Hyper-V Containers Linux virtual machine FAQs
Why load a Linux Virtual Machine for Hyper-V containers?
Installing a Linux virtual machine for running Linux containers in Hyper-V is a straightforward way to run your Linux containers. In addition, it provides easy separation from your native Hyper-V environment. In addition, there are other documented ways to run Linux containers, including LinuxKit. However, many of these use features that may not be supported in production, like WSL or Docker desktop. In addition, many instructions from Microsoft and Docker are stale on this subject.
Are Hyper-V containers free?
Yes, Hyper-V containers come at no cost outside the Windows Server license you use to run Hyper-V.
Are there other ways to run Linux containers in Hyper-V?
Microsoft and Docker have launched Docker Enterprise with the capability of running both Windows and Linux containers on a Windows Server container host for production workloads. If you are looking for a free solution, you can use Docker Desktop (non-enterprise version) and Windows Subsystem for Linux. However, these are not supported for running production workloads. You can also use the LinuxKit approach linked above. However, the downside to this is you won’t be able to run Windows containers alongside Linux containers. You must choose which you will run on your Hyper-V host or enable and disable LinuxKit as needed.
Wrapping up
Installing a Linux virtual machine in your Hyper-V environment allows having the best of both worlds in Hyper-V. You can run both Windows and Linux containers. Windows containers can run natively on the Hyper-V host with Docker. Then, you can use the Linux container host running as a virtual machine for your Linux containers. Since there is minimal overhead to running most Linux containers, you can configure the VM with a small footprint in the environment.
Read More:
Hyper-V Mastery: A Step-by-Step Guide for Beginners to Elevate Your IT Skills and Boost Your Career
Beginners’ Guide for Microsoft Hyper-V: How To Install Docker Container on Windows Server – Part 27
Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.