Run Linux containers on Windows | Ubuntu (2024)

1. Overview

It is now possible to run Docker containers on Windows 10 and Windows Server, leveraging Ubuntu as a hosting base.

Imagine running your own Linux applications on Windows, using a Linux distribution you are comfortable with: Ubuntu!

It is now possible to do so using the power of Docker technology and Hyper-V virtualization on Windows.

Run Linux containers on Windows | Ubuntu (1)

Originally authored by Mathieu Trudel-Lapierre.

2. Requirements

You will need a 64-bit x86 PC with 8GiB of RAM running Windows 10 or Windows Server, updated to include the Windows 10 Fall Creator update, released October 2017.

You will also need a recent installation of Docker.

Finally, you will need to make sure you have installed a program for decompressing the Ubuntu host container image, e.g. 7-Zip or XZ Utils

3. Install Docker for Windows

Download Docker for Windows from Docker Store.

Run Linux containers on Windows | Ubuntu (2)

Once downloaded, proceed with the installation steps, and either logout or reboot of your system as indicated by the installer.

Run Linux containers on Windows | Ubuntu (3)

After reboot, Docker will be started. Docker requires that the Hyper-V feature is enabled, so if necessary will ask you to enable it and restart. Click OK for Docker to enable Hyper-V and restart your system.

Run Linux containers on Windows | Ubuntu (4)

4. Download the Ubuntu container image

Download the latest Ubuntu container image for Windows from the Canonical Partner Images website

Once downloaded, extract the image, using e.g. 7-Zip, or XZ Utils:

C:\Users\mathi\> .\xz.exe -d xenial-container-hyper-v.vhdx.xz

5. Prepare the container environment

First, create two directories:

Run Linux containers on Windows | Ubuntu (5)

Create C:\lcow, which will be used as scratch space for Docker while preparing the containers.

Run Linux containers on Windows | Ubuntu (6)

Also create C:\Program Files\Linux Containers. This is where the Ubuntu container image will live.

You will need to give this folder extra permissions to allow Docker to use the images from it. Run the following Powershell script in an administrator Powershell window:

param([string] $Root)# Give the virtual machines group full control$acl = Get-Acl -Path $Root$vmGroupRule = new-object System.Security.AccessControl.FileSystemAccessRule("NT VIRTUAL MACHINE\Virtual Machines", "FullControl","ContainerInherit,ObjectInherit", "None", "Allow")$acl.SetAccessRule($vmGroupRule)Set-Acl -AclObject $acl -Path $Root

Save this file as set_perms.ps1 and run it:

TIP You may need to run ‘Set-ExecutionPolicy -Scope process unrestricted’ to be allowed to run unsigned Powershell scripts.

Run Linux containers on Windows | Ubuntu (7)

C:\Users\mathi\> .\set_perms.ps1 "C:\Program Files\Linux Containers"C:\Users\mathi\>

Now, copy the Ubuntu container image .vhdx file that was decompressed at the previous step to uvm.vhdx under C:\Program Files\Linux Containers.

6. More Docker preparation

Docker for Windows requires some pre-release features in order to work with Hyper-V isolation. While these features are not yet available in the Docker CE installation that was done previously, the necessary files can be downloaded from master.dockerproject.org.

Run Linux containers on Windows | Ubuntu (8)

Retrieve dockerd.exe and docker.exe from master.dockerproject.org, and put the two programs somewhere safe, such as in your own folder. They will be used to start the Ubuntu container in the next step.

7. Run an Ubuntu container on Hyper-V

You’re now ready to start your container. First, open a Command-line prompt (cmd.exe) as Administrator, and start dockerd.exe with the right environment:

C:\Users\mathi\> set LCOW_SUPPORTED=1C:\Users\mathi\> .\dockerd.exe -D --data-root C:\lcow

Docker already running?
If the Docker installer sets Docker to run automatically at boot, you may need to quit the already running daemon, via its toolbar icon, before running the above commands.

Then, start a Powershell window as Administrator; and run docker.exe, instructing it to pull the image for your container:

C:\Users\mathi\> .\docker.exe pull ubuntu

Run Linux containers on Windows | Ubuntu (9)

Run Linux containers on Windows | Ubuntu (10) Run Linux containers on Windows | Ubuntu (11)

We can now finally start the container. Run docker.exe again, and tell it to run the new image:

C:\Users\mathi\> .\docker.exe run -it ubuntu

Run Linux containers on Windows | Ubuntu (12)

Congratulations! You have successfully set up your system to use containers with Hyper-V isolation on Windows, and have run your very own Ubuntu container.

8. Getting help

Was this tutorial useful?

Thank you for your feedback.

Run Linux containers on Windows | Ubuntu (2024)

FAQs

Can I run a Linux container on Windows? ›

Docker has been able to run Linux containers on Windows desktop since it was first released in 2016 (before Hyper-V isolation or Linux containers on Windows were available) using a LinuxKit based virtual machine running on Hyper-V.

How do I switch to Linux containers in Windows? ›

Run Your First Linux Container

You can toggle this by selecting Switch to Linux Containers from the action menu when clicking on the Docker whale icon in the system tray. If you see Switch to Windows Containers , then you are already targeting the Linux daemon. The container should run, print "hello_world", then exit.

Can we run Ubuntu Docker on Windows? ›

We successfully installed a complete Ubuntu terminal environment in minutes with Windows Subsystem for Linux (WSL) on Windows. Then, We installed Docker Desktop on Windows. After making the necessary settings in the Docker Desktop, we run Docker commands in the Windows terminal.

How do I run a Docker container in Windows? ›

To run your image as a container:
  1. In Docker Desktop, go to the Images tab.
  2. Next to your image, select Run.
  3. Expand the Optional settings.
  4. In Host port, specify 8089 .
  5. Select Run.

Can I run containers on Windows? ›

Run a Windows container using Windows Admin Center

You can use Windows Admin Center to run your containers locally.

Can WSL run Linux containers? ›

However, since WSL 2 now runs on a Linux kernel with full system call capacity, Docker can fully run in WSL 2. This means that Linux containers can run natively without emulation, resulting in better performance and interoperability between your Windows and Linux tools.

What is the difference between Linux containers and Windows containers? ›

The biggest difference is the container image. Windows images are larger than Linux images. When you run your container the Docker image is downloaded and it takes a bit longer than downloading a Docker image based on Linux.

Can you run Docker on Windows without Docker Desktop? ›

Before we continue, we need to understand that Docker Engine is the fundamental runtime that powers Docker containers, while Docker Desktop is a higher-level application that includes Docker Engine. Hence, Docker Engine can also be used independently without Docker Desktop on local machine.

What is Kubernetes vs Docker? ›

While Docker is a container runtime, Kubernetes is a platform for running and managing containers from many container runtimes. Kubernetes supports numerous container runtimes including Docker, containerd, CRI-O, and any implementation of the Kubernetes CRI (Container Runtime Interface).

Can I install Linux Docker on Windows? ›

To run Windows containers, you need Windows 10 or Windows 11 Professional or Enterprise edition. Windows Home or Education editions only allow you to run Linux containers. Docker only supports Docker Desktop on Windows for those versions of Windows that are still within Microsoft's servicing timeline .

What is the difference between WSL and Docker? ›

WSL 2 adds support for "Linux distros" to Windows, where each distro behaves like a VM except they all run on top of a single shared Linux kernel. Docker Desktop does not require any particular Linux distros to be installed. The docker CLI and UI all work fine from Windows without any additional Linux distros.

Can I use Linux on Windows using Docker? ›

If you need Linux containers and Windows containers you can use Docker Desktop to run Windows containers and WSL to run Linux containers and forward the necessary ports to the WSL host from the Windows host.

Are there Windows Docker containers? ›

Microsoft provides a number of tools and platforms to help you develop and deploy apps in containers: Run Windows-based or Linux-based containers on Windows 10 for development and testing using Docker Desktop, which makes use of containers functionality built-in to Windows.

How to run Ubuntu in Docker Desktop? ›

Recommended approach to install Docker Desktop on Ubuntu:
  1. Set up Docker's package repository. See step one of Install using the apt repository.
  2. Download latest DEB package .
  3. Install the package with apt as follows: $ sudo apt-get update $ sudo apt-get install ./docker-desktop-<version>-<arch>.deb. Note.

What is the difference between Docker and Docker desktop? ›

Docker Engine is the fundamental containerization engine that runs on servers and manages containers, while Docker Desktop is a developer-focused tool that includes Docker Engine along with additional features to simplify the development and testing of containerized applications on local machines.

What is the difference between Linux container and Windows container? ›

On Windows, you have two ways of running containers. One is to run containers directly on the host, using what Microsoft calls Windows Server Containers. The other is to use specialized Hyper-V instances to host your containers. On Linux, there is no official equivalent of Hyper-V mode for containers.

Should I use Windows or Linux containers for Docker? ›

Even though there is no functional difference between Docker on Windows and Linux environments, the installation process on Linux is a bit faster (an apt-get install is quicker than installing a Windows package), and the shell is easier to access on Linux.

Can Kubernetes run Windows and Linux containers? ›

Windows nodes in Kubernetes

In order to run Windows containers, your Kubernetes cluster must include multiple operating systems. While you can only run the control plane on Linux, you can deploy worker nodes running either Windows or Linux.

Can you run a Windows Docker container on a Linux host? ›

You could run Windows containers and switch to Linux containers, run Linux containers (from the GUI or change context from terminal) and you should be able to run both containers at the same time, but they will not have a common network as one will run in a Linux VM, the other will either have process isolation on ...

Top Articles
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 6580

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.