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

  1. Windows vs Linux containers
  2. Create a new Hyper-V Linux Virtual Machine
  3. Change to make for Generation 2 Hyper-V Linux VM
  4. Beginning the installation of Ubuntu 22.04
  5. Hyper-V Containers Linux virtual machine FAQs
  6. Why load a Linux Virtual Machine for Hyper-V containers?
  7. Are Hyper-V containers free?
  8. Are there other ways to run Linux containers in Hyper-V?
  9. Wrapping up

Protect Your Data with BDRSuite

Cost-Effective Backup Solution for VMs, Servers, Endpoints, Cloud VMs & SaaS applications. Supports On-Premise, Remote, Hybrid and Cloud Backup, including Disaster Recovery, Ransomware Defense & more!

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.

Download Banner

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.

Linux Containers

Begin the new virtual machine wizard

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.

Linux Containers

Choose the name and location for the new Linux VM

Specify the Hyper-V Generation of the new Linux virtual machine.

Linux Containers

Select the Hyper-V generation of the virtual machine

Assign the configured memory for the new Linux virtual machine.

Linux Containers

Configuring memory for the new 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.

Linux Containers

Select the Hyper-V virtual networking you want to use

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.

Linux Containers

Connecting to an existing hard disk or creating a new virtual disk

Select the installation image for installing your Linux virtual machine.

Linux Containers

Select the installation media for the 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.

Linux Containers

Ready to complete the new virtual machine wizard

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.

Linux Containers

Changing security settings for the Ubuntu Server virtual machine

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.

Linux Containers

Booting the Ubuntu Server virtual machine

Choose your installation language.

Linux Containers

Choose your installation language

Choose if you want to update the installer to the latest version.

Linux Containers

Update your Ubuntu installer

Choose your keyboard configuration.

Linux Containers

Choose your keyboard configuration

Choose your installation type.

Linux Containers

Choose your installation type

Configure your network settings.

Linux Containers

Configure your network settings

If you need to configure proxy settings, you can do that on the next screen.

Linux Containers

Configure proxy settings if needed

Configure your storage settings.

Linux Containers

Configure your storage settings

Verify your storage configuration.

Linux Containers

Verify your storage configuration

Confirm disk formatting and destruction of existing data.

Linux Containers

Confirm the formatting of your Linux hard disk

Set up your local user and password for logging into your Ubuntu Server system.

Linux Containers

Confirm your profile setup, including username and password

Verify installing OpenSSH Server.

Linux Containers

Verify OpenSSH installation

Specify any additional packages you want to install.

Linux Containers

Specify additional packages to install in Ubuntu

The Ubuntu Server installation begins.

Linux Containers

Beginning the installation of Ubuntu Server

The installation of Ubuntu Server 22.04 completes successfully. Select Reboot Now to reboot your Ubuntu Server installation.

Linux Containers

Ubuntu Server 22.04 installation completes successfully

Once rebooted, we can log in to our Ubuntu Server 22.04 installation.

Linux Containers

Successfully logged into the new 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.

Rate this post