Install Docker on Windows

Completed

To start with Docker, you first need to install it on your development machine. The type of installation depends on your operating system. The installation is different on a Windows 10 machine than on a Windows Server machine. You need at least Windows 10 Professional or Enterprise with the Anniversary Update (version 1607), Windows Server 2016, or Windows Server 2019.

Windows containers on Docker can run in two distinct modes of runtime isolation:

  • Process Isolation

  • Hyper-V Isolation

The differences between these modes are discussed later in this module. Because Windows containers can run in two distinct modes, you will need to install or activate Hyper-V on the development machine. On Windows 10, Hyper-V is required to run Docker, even if you don't use Hyper-V Isolation. To install Hyper-V, you also need to use different PowerShell commands on Windows 10 and a Windows Server machine.

In Windows, search for Windows PowerShell and then run it as an administrator.

Screenshot of how to search for Windows PowerShell.

In Windows 10, you can install Hyper-V by running the following command:

Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V

For Windows Server, you can use following command:

Install-WindowsFeature Hyper-V

A situation might occur when you want to run Docker within a virtual machine instead of your local machine. That scenario is possible, but you need to configure Nested Virtualization, which is not covered in this module. For more information, see Run Hyper-V in a Virtual Machine with Nested Virtualization.

After Hyper-V installation, you can install Docker.

This section begins with Windows Server, where you can use the PowerShell module published by Microsoft called the DockerMicrosoftProvider. This module enables the container feature in Windows and installs the Docker engine and client.

  1. Open Windows PowerShell as an administrator (elevated PowerShell session) and run following command:

    Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

    You need to accept with Y (Yes).

    Tip

    Run the normal Windows PowerShell application, not the ISE, because it doesn't work well with Docker.

  2. Install the package with the Install-Package command and then accept with A (Yes to All).

    Install-Package -Name Docker -ProviderName DockerMsftProvider

  3. Restart your machine.

    Restart-Computer -Force

For Windows 10 machines, you can't use the DockerMicrosoftProvider module. You need to download and install Docker Desktop (Docker Desktop for Windows) by creating a free Docker account. During the installation, you can set the default container type to Windows containers. You can also switch the type after the installation. Therefore, you can right-click the Docker item in the Windows system tray and then select Switch to Windows Containers.

Screenshot of the Switch to Windows containers option.

After installation, you can test if Docker is installed successfully. Docker, and more specific containers, are not new but are already used substantially in the Linux world. Therefore, working with Docker involves working with commands. Other GUI tools are available that you can use to run the commands. In this module, you'll use the Docker commands by using the PowerShell console and by using an extension in Visual Studio Code.

To test the installation, you can run the following command to retrieve the installed version.

docker version