How to Install and Run Docker on Windows Server 2016, 2019, 2022

How to Install and Run Docker on Windows Server 2016, 2019, 2022. In this tutorial we will introduce Docker and how it works with it’s main advantages then move onto installation phase with how to install Docker using PowerShell.

Docker is one of the most widely used containerization platform used by developers. It allows developers to create, deploy, and run applications with the help of containers.

Next in this article How to Install and Run Docker on Windows Server 2016, 2019, 2022 is to introduce Docker.

What Is Docker?

The Docker is an open source platform that allows you to build, deploy, run, update, and manage containers. They are standardized, executable components that integrate application source code with operating system libraries and dependencies they need to run that code in any environment.

With the help of containers, the process of simplifying the development and delivery of distributed applications becomes effortless. The platform is highly popular among organizations transforming themselves to cloud native developments and hybrid multi cloud environments. Therefore, by using Docker, you will tend to acquire the following additional advantages:

Docker Benefits

  • Light Weight – The Docker containers do not have to carry the payload of an entire OS instance and hypervisor. They only require the OS processes and dependencies for executing the code. Also, since their sizes are measured in megabytes, you can make better use of hardware capacity and have faster start-up times.
  • Greater Resource Efficiency – With the help of Docker containers, you can run several copies of the same application on the hardware as many times as you want, thereby reducing cloud spending.
  • Improved Developer Productivity – Write and run only once a time a containerized application anywhere. In comparison to VMs, they will run faster and deploy, provision and restart effortlessly. This way, you can make them ideal for usage in continuous integration and continuous delivery (CI/CD) pipelines. It will also be a better fit for development teams adopting Agile and DevOps practices.
  • Improved And Seamless Container PortabilityDocker containers tend to run without modification across any desktop, data center, and cloud environment.
  • Automated Container Creation – Docker tends to build a container automatically according to the application source code.
  • Shared Container Libraries – Docker enables you to access open source libraries, which include numerous user contributed containers.
  • Containers Reuse – In Docker, you can use existing containers as base images, especially templates for building new containers.
  • Container Versioning – Docker trackers the versions of a computer image, get back to previous versions and then identify who built it and when. They also upload only deltas between an existing version and a new one.

Moreover, if you use containers, you tend to acquire benefits, like improved app quality, faster response to market changes, etc.

How Does Docker Work?

Docker work by packaging, provisioning, and running containers. Its technology is available to the operating system. A container packages the application service or function will every library, configuration files, dependencies, and other necessary parts and parameters to operate. Every container contributes to the service of one underlying operating system.

Moreover, Docker images constitute the dependencies required for executing code inside a container. This way, containers that move between Docker environments with similar OS work with no changes.

Docker also uses resource isolation in the OS Kernel to run several containers on the same OS. It is not as same as Virtual Machines (VMs) that encapsulate an entire OS with executable codes on an abstracted layer of physical hardware resources.

On the other hand, Docker was developed to work on the Linux platform. However, it has extended its offer to provide support to non Linux Operating systems too. It includes Microsoft Windows and Apple OS X. Docker also has the version for Amazon Web Services (AWS) and Microsoft Azure.

Next in this post we will show you how to install and run Docker on Windows server 2016 / 2019 and 2022.

Enable the Containers Feature

By default, the container features are not enabled on Windows server machine. So you will need to enable it first.

Open your Windows PowerShell and run the following command to enable the containers features:

				
					Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
				
			

The above command will install the Docker-Microsoft PackageManagement Provider from the PowerShell Gallery. 

Install Docker Engine

After the Containers feature is enabled on Windows Server, open your powershell windows and install the latest Docker Engine and Client by running the command below:

				
					Install-Package -Name docker -ProviderName DockerMsftProvider
				
			

Once the Docker is installed, you will get the following output:

				
					WARNING: A restart is required to enable the containers feature. Please restart your machine.

Name                           Version          Source           Summary                                             
----                           -------          ------           -------                                             
Docker                         20.10.9          DockerDefault    Contains Docker EE for use with Windows Server. 

				
			

Next, you will need to restart your system to enable the docker features. You can run the following command to restart the system:

				
					Restart-Computer -Force
				
			

Verify the Docker Installation

You can verify the installed version of  Docker using the following command in the powershell window:

				
					Get-Package -Name Docker -ProviderName DockerMsftProvider
				
			

You will get the following output:

				
					Name                           Version          Source                           ProviderName                        
----                           -------          ------                           ------------                        
docker                         20.10.9          DockerDefault                    DockerMsftProvider                  
				
			

You can also run the following command to see the Docker version information:

				
					docker version
				
			

You should see the Docker version information in the following output:

				
					Client: Mirantis Container Runtime
 Version:           20.10.9
 API version:       1.41
 Go version:        go1.16.12m2
 Git commit:        591094d
 Built:             12/21/2021 21:34:30
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Mirantis Container Runtime
 Engine:
  Version:          20.10.9
  API version:      1.41 (minimum version 1.24)
  Go version:       go1.16.12m2
  Git commit:       9b96ce992b
  Built:            12/21/2021 21:33:06
  OS/Arch:          windows/amd64
  Experimental:     false

				
			

If you want to get detailed information of Docker package, run the following command:

				
					docker info
				
			

You should see the following output:

				
					Client:
 Debug Mode: false
 Plugins:
  cluster: Manage Docker clusters (Docker Inc., v1.1.0-8c33de7)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 19.03.2
 Storage Driver: windowsfilter
  Windows: 
 Logging Driver: json-file
 Plugins:
  Volume: local
  Network: ics l2bridge l2tunnel nat null overlay transparent
  Log: awslogs etwlogs fluentd gcplogs gelf json-file local logentries splunk syslog
 Swarm: inactive
 Default Isolation: process
 Kernel Version: 10.0 14393 (14393.3808.amd64fre.rs1_release.200707-2105)
 Operating System: Windows Server 2016 Standard Version 1607 (OS Build 14393.3808)
 OSType: windows
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.999GiB
 Name: CLOUD-0Q59R832Q
 ID: BTXL:3ZPL:A7MZ:FNCV:UZRU:VG7I:YU7X:DERR:2Q2Y:2YNL:SYGN:AGYT
 Docker Root Dir: C:\ProgramData\docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

				
			

Run the Docker Container

Firstly, start the Docker service using the following command:

				
					Start-Service Docker
				
			

Next, download the Docker dotnet nano server container image using the following command:

				
					docker pull mcr.microsoft.com/dotnet/samples:dotnetapp-nanoserver-2009
				
			

Once the image is downloaded, you can run the container from the downloaded image using the following command:

				
					docker run mcr.microsoft.com/dotnet/samples:dotnetapp-nanoserver-2009
				
			

Run Linux Container on Windows

By default, Docker on Windows machine can only run Windows container. In order to use Linux containers on Windows Server, you need to use the Docker Enterprise Edition Preview which includes a full LinuxKit system for running Docker Linux containers.

The first thins is to remove your Windows Docker engine using the following command:

				
					Uninstall-Package -Name docker -ProviderName DockerMSFTProvider
				
			

Secondly,  install Docker for Linux by running the following command:

				
					Install-Module DockerProvider
Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview
				
			

Thirdly, enable LinuxKit system for running Linux containers using the following command:

				
					[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")
				
			

The next step is to  start the Docker service with the following command:

				
					Restart-Service docker
				
			

Then download and run your first Linux container using the following command:

				
					docker run -it --rm ubuntu /bin/bash
				
			

This command will download the latest Ubuntu container image, create the container and connect to the container shell as shown below: 

				
					root@21340a2fsf7e2:/#
				
			

You can now run the following command inside the container to verify the Ubuntu version:

				
					root@21340a2fsf7e2:/# cat /etc/os-release 
 NAME="Ubuntu"
 VERSION="22.04.1 LTS (Jammy Jellyfish )"
 ID=ubuntu
 ID_LIKE=debian
 PRETTY_NAME="Ubuntu 22.04.1 LTS"
 VERSION_ID="22.04"
 HOME_URL="https://www.ubuntu.com/"
 SUPPORT_URL="https://help.ubuntu.com/"
 BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
 PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
 VERSION_CODENAME=Jammy Jellyfish
 UBUNTU_CODENAME=Jammy Jellyfish
				
			

To disconnect from the container, run the following command:

				
					root@21340a2fsf7e2:/# exit
				
			

How to Use Docker

Docker provides many useful commands that help developers or system administrators to easily manage Docker containers from the command line.

You can use the –name option with Docker to assign a container name when running a new container. For example, to launch a new container from the debian:latest images and assigned a name debian-container, run the following command:

				
					docker.exe container run --name debian-container debian:latest
				
			

After starting the container, you can see the status of all container using the following command:

				
					docker.exe ps -a
				
			

There are two ways of running a container, in attached mode and in detached mode. By default, Docker runs the container in attached mode. In the attached mode, you will be connected to the terminal session, where it displays output and messages.

If you want to run a container in detached mode, use the -d flag:

				
					docker.exe container run -d debian:latest
				
			

You can run a container in interactive mode with Docker. In this mode, you can run commands inside the container. You can use the following command to run a container in an interactive mode:

				
					docker container run -it debian:latest /bin/bash
				
			

If you want to start, stop or remove the Docker container, run the following commands:

				
					docker container start container-name
docker container stop container-name
docker container rm container-name
				
			

Great! You have read How to Install and Run Docker on Windows Server 2016, 2019, 2022 until the very end. let’s conclude. 

How to Install and Run Docker on Windows Server 2016, 2019, 2022 Conclusion

In this post we illustrated how to install Docker CE on Windows server 2016, 2019, and 2022. We also explained how to run dotnet container in Windows server. I hope this guide will help a lot to run and manage the Docker container. Docker’s containers technology makes development highly scalable as it separates your applications from your infrastructure to be able to deliver software quickly. Shipping, testing and deploying the code is made quickly with less delays in applications delivery.

Windows Server provides many great features to run your Docker containers, including Hyper V isolation for additional security and kernel protection. Also, Microsoft Windows Server can run both Windows and Linux containers meaning you can have a mixed environment supporting applications needing both Windows and Linux components.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

3.7 3 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x