Docker desktop для windows server 2016

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?

install and Run Docker on Windows Server 2016, 2019, 2022.

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 Portability – Docker 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?

how docker works

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.

				
					Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
				
			

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

Run Docker Engine on Windows in Azure

Run Docker Engine on Windows in AWS

Run Docker Engine on Windows in GCP

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:

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:

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:

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

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:

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: 

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:

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.

Today, Microsoft announced the general availability of Windows Server 2016, and with it, Docker engine running containers natively on Windows. This blog post describes how to get setup to run Docker Windows Containers on Windows 10 or using a Windows Server 2016 VM. Check out the companion blog posts on the technical improvements that have made Docker containers on Windows possible and the post announcing the Docker Inc. and Microsoft partnership.

Before getting started, It’s important to understand that Windows Containers run Windows executables compiled for the Windows Server kernel and userland (either windowsservercore or nanoserver). To build and run Windows containers, a Windows system with container support is required.

Windows 10 with Anniversary Update

For developers, Windows 10 is a great place to run Docker Windows containers and containerization support was added to the the Windows 10 kernel with the Anniversary Update (note that container images can only be based on Windows Server Core and Nanoserver, not Windows 10). All that’s missing is the Windows-native Docker Engine and some image base layers.

The simplest way to get a Windows Docker Engine is by installing the Docker for Windows public beta (direct download link). Docker for Windows used to only setup a Linux-based Docker development environment (slightly confusing, we know), but the public beta version now sets up both Linux and Windows Docker development environments, and we’re working on improving Windows container support and Linux/Windows container interoperability.

With the public beta installed, the Docker for Windows tray icon has an option to switch between Linux and Windows container development. For details on this new feature, check out Stefan Scherers blog post.

Switch to Windows containers and skip the next section.

Switching to windows containers

Windows Server 2016

Windows Server 2016 is the where Docker Windows containers should be deployed for production. For developers planning to do lots of Docker Windows container development, it may also be worth setting up a Windows Server 2016 dev system (in a VM, for example), at least until Windows 10 and Docker for Windows support for Windows containers matures.

For Microsoft Ignite 2016 conference attendees, USB flash drives with Windows Server 2016 preloaded are available at the expo. Not at ignite? Download a free evaluation version and install it on bare metal or in a VM running on Hyper-V, VirtualBox or similar. Running a VM with Windows Server 2016 is also a great way to do Docker Windows container development on macOS and older Windows versions.

Once Windows Server 2016 is running, log in, run Windows Update to ensure you have all the latest updates and install the Windows-native Docker Engine directly (that is, not using “Docker for Windows”). Run the following in an Administrative PowerShell prompt:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Name DockerMsftProvider -Force
Install-Package -Name docker -ProviderName DockerMsftProvider -Force
Restart-Computer -Force

Docker Engine is now running as a Windows service, listening on the default Docker named pipe. For development VMs running (for example) in a Hyper-V VM on Windows 10, it might be advantageous to make the Docker Engine running in the Windows Server 2016 VM available to the Windows 10 host:

# Open firewall port 2375
netsh advfirewall firewall add rule name="docker engine" dir=in action=allow protocol=TCP localport=2375

# Configure Docker daemon to listen on both pipe and TCP (replaces docker --register-service invocation above)
Stop-Service docker
dockerd --unregister-service
dockerd -H npipe:// -H 0.0.0.0:2375 --register-service
Start-Service docker

The Windows Server 2016 Docker engine can now be used from the VM host by setting DOCKER_HOST:

$env:DOCKER_HOST = "<ip-address-of-vm>:2375"

See the Microsoft documentation for more comprehensive instructions.

Running Windows containers

First, make sure the Docker installation is working:

> docker version
Client:
Version:      1.12.1
API version:  1.24
Go version:   go1.6.3
Git commit:   23cf638
Built:        Thu Aug 18 17:32:24 2016
OS/Arch:      windows/amd64
Experimental: true

Server:
Version:      1.12.2-cs2-ws-beta
API version:  1.25
Go version:   go1.7.1
Git commit:   62d9ff9
Built:        Fri Sep 23 20:50:29 2016
OS/Arch:      windows/amd64

Next, pull a base image that’s compatible with the evaluation build, re-tag it and to a test-run:

docker pull microsoft/windowsservercore
docker run microsoft/windowsservercore hostname
69c7de26ea48

Building and pushing Windows container images

Pushing images to Docker Cloud requires a free Docker ID. Storing images on Docker Cloud is a great way to save build artifacts for later user, to share base images with co-workers or to create build-pipelines that move apps from development to production with Docker.

Docker images are typically built with docker build from a Dockerfile recipe, but for this example, we’re going to just create an image on the fly in PowerShell.

"FROM microsoft/windowsservercore `n CMD echo Hello World!" | docker build -t <docker-id>/windows-test-image -

Test the image:

docker run <docker-id>/windows-test-image
Hello World!

Login with docker login and then push the image:

docker push <docker-id>/windows-test-image

Images stored on Docker Cloud available in the web interface and public images can be pulled by other Docker users.

Using docker-compose on Windows

Docker Compose is a great way develop complex multi-container consisting of databases, queues and web frontends. Compose support for Windows is still a little patchy and only works on Windows Server 2016 at the time of writing (i.e. not on Windows 10).

To develop with Docker Compose on a Windows Server 2016 system, install compose too (this is not required on Windows 10 with Docker for Windows installed):

Invoke-WebRequest https://dl.bintray.com/docker-compose/master/docker-compose-Windows-x86_64.exe -UseBasicParsing -OutFile $env:ProgramFiles\docker\docker-compose.exe

To try out Compose on Windows, clone a variant of the ASP.NET Core MVC MusicStore app, backed by a SQL Server Express 2016 database. A correctly tagged microsoft/windowsservercore image is required before starting.

git clone https://github.com/friism/Musicstore
...
cd Musicstore
docker-compose -f .\docker-compose.windows.yml build
...
docker-compose -f .\docker-compose.windows.yml up
...

To access the running app from the host running the containers (for example when running on Windows 10 or if opening browser on Windows Server 2016 system running Docker engine) use the container IP and port 5000. localhost will not work:

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" musicstore_web_1
172.21.124.54

If using Windows Server 2016 and accessing from outside the VM or host, simply use the VM or host IP and port 5000.

Summary

This post described how to get setup to build and run native Docker Windows containers on both Windows 10 and using the recently published Windows Server 2016 evaluation release. To see more example Windows Dockerfiles, check out the Golang, MongoDB and Python Docker Library images.
Please share any Windows Dockerfiles or Docker Compose examples your build with @docker on Twitter using the tag #windows. And don’t hesitate to reach on the Docker Forums if you have questions.

More Resources:

  • Sign up to be notified of GA and the Docker Datacenter for Windows Beta
  • Docker for Windows Server
  • Learn more about the Docker and Microsoft partnership

Enterprise servers are not always exposed to the internet and are often sitting behind firewalls with restrictions to prohibit any malicious activity on an internet-facing server. But to install a Docker image from the Docker Hub, you need internet access. To overcome this, you can configure a Docker client to use a proxy server if one is available, but there is another way around this, which we will discuss in the following high-level steps.

Contents

  1. Install Docker with internet access
  2. Pull the image from the Docker Hub and export it
  3. Download Docker Enterprise
  4. Install Docker Enterprise on Windows Server 2016
  5. Load and run the image
  6. Conclusion
  • Author
  • Recent Posts

Prateek Singh is an infrastructure developer, an avid PowerShell blogger, and a community contributor. In 2017, FeedSpot recognized his blog RidiCurious.com as among the «Top 50 PowerShell blogs in the world.» All of his PowerShell projects and modules are open-sourced at GitHub, and you can reach out to him on Twitter at @SinghPrateik.

Install Docker with internet access

Log in to a Windows 10 machine that has internet access, probably your laptop or workstation, and use the following URL for instructions to install Docker on Windows 10.

Once the installation is complete, run a PowerShell console and verify the Docker installation on Windows 10:

docker --version
Get-Service *docker*

Verify the Docker installation

Verify the Docker installation

Pull the image from the Docker Hub and export it

Now use Docker to download or pull a Docker test image from the Docker Hub. We’ll later use this image to test a Docker installation on Windows Server 2016.

docker pull hello-world:nanoserver-sac2016

After downloading the image, use the docker save command to export and save the image to a file («nano.tar» for example).

docker save -o nano.tar hello-world:nanoserver-sac2016

This will save the image as «nano.tar» in your current working directory.

Download Docker Enterprise

Now that we have a Docker image, let’s use PowerShell to download «Docker Enterprise Edition» to our local workstation as a zip file. We will need this because we don’t have internet access on Windows Server 2016.

$URL = ‘https://download.docker.com/components/engine/windows-server/17.06/docker-17.06.2-ee-16.zip’

invoke-webrequest -UseBasicparsing -Outfile docker-17.06.2-ee-16.zip -Uri $URL

We can now copy the two files: Docker Enterprise Edition for Windows Server 2016 as a zipped file and a test Docker image we have saved as «nano.tar» in the previous step to the target Windows 2012 Server.

Install Docker Enterprise on Windows Server 2016

Let’s switch to the Windows 2012 Server and assume you have placed the Docker Enterprise installation files and the image on D:\. So the first step required is installing the container feature on the Windows 2012 Server and then rebooting the machine when prompted.

# Install Docker
Install-WindowsFeature containers | Out-Null

Once the machine is up and running again, launch a PowerShell console. Then unzip the compressed file and move the Docker executables to the system’s program files.

# cd <path to the zip file and docker image>
cd d:\

# Extract the archive.
Expand-Archive docker-17.06.2-ee-16.zip -DestinationPath $Env:ProgramFiles  Force

Next, use the following PowerShell commands to add the Docker folder location to the system’s PATH variable and run the Docker executable as a service.

# Add Docker to the path for the current session and to PATH to persist across sessions.
$env:path += ";$env:ProgramFiles\docker"

$newPath = "$env:ProgramFiles\docker;" +
[Environment]::GetEnvironmentVariable("PATH",
[EnvironmentVariableTarget]::Machine)

[Environment]::SetEnvironmentVariable("PATH", $newPath,
[EnvironmentVariableTarget]::Machine)

# Register the Docker daemon as a service.
dockerd --register-service

# Start the Docker service.
Start-Service docker

Set up the PATH variable and Docker service

Set up the PATH variable and Docker service

This will complete the Docker Enterprise setup on Windows Server 2016.

Load and run the image

From the PowerShell console, use the docker load command to load the «nano.tar» file (the Docker image) into our current session. Verify the image is loaded and available and the Docker service is running.

# docker load image offline
docker load -i nano.tar

# list all available images
docker images

# make sure docker service is running
Get-Service *docker

Load the Docker image

Load the Docker image

Now run the test container image using the docker run command. If you get results like in the following screenshot, this means installation was successful and the container is running properly.

Subscribe to 4sysops newsletter!

# run the test container
docker run hello-world:nanoserver-sac2016

Run test containers

Run test containers

Conclusion

Downloading Docker container images from the Docker Hub or Registry is often restricted on enterprise servers. One workaround is to set up a proxy server to allow such access. But in case this is not available or allowed, you can pull and save a Docker image to a machine (Windows 10) that has internet access. Later, you can export the image as a compressed file and move it to the enterprise server (Windows Server 2016) that cannot access the internet. Once you have the image as a compressed file, you can directly load it using the docker load -i <image file name> command on Windows Server 2016 and run containers with the image.

avataravatar

This multi-part blog series will show how to configure, build, and run Docker containers on Windows. The first part showed how to setup Windows Server 2016 on Virtual Box for Docker Containers. This part will install the operating system images and configure Docker. Instructions are available at msdn.microsoft.com/virtualization/windowscontainers/deployment/deployment.

How to Install Docker in Windows Server 2016 Container Feature

Start PowerShell:
windows-2016-docker-1-

Install the container feature:
windows-2016-docker-2

Restart the Virtual Machine:
windows-2016-docker-3

Install Windows Server 2016 Base Docker Image

Base operating system can be installed using ContainerImage PowerShell module. Install the module as:
windows-2016-docker-4

See the list of operating system images that are available:
windows-2016-docker-5

Install the Windows Server Core base OS image:
windows-2016-docker-6 windows-2016-docker-7

Install Docker on Windows Server 2016

Download the script to install Docker:
windows-2016-docker-8

Run the script:
windows-2106-docker-9

Check Docker version:
windows-2016-docker-11

Check the list of images and tag the base OS image to latest:
windows-2106-docker-10
Check docker --help command:
 windows-2016-docker-12

Subsequent blogs will show how other fun things with Docker on Windows Server 2016!

Some further topics to read …

  • Windows Server Containers – Quick Start
  • Windows Server 2016 Technology Preview 5
  • Docker Documentation
  • Getting Started with Docker for Java developers

Posted by Arun Gupta, VP, Developer Advocacy, Couchbase

Arun Gupta is the vice president of developer advocacy at Couchbase. He has built and led developer communities for 10+ years at Sun, Oracle, and Red Hat. He has deep expertise in leading cross-functional teams to develop and execute strategy, planning and execution of content, marketing campaigns, and programs. Prior to that he led engineering teams at Sun and is a founding member of the Java EE team.

Gupta has authored more than 2,000 blog posts on technology. He has extensive speaking experience in more than 40 countries on myriad topics and is a JavaOne Rock Star for three years in a row. Gupta also founded the Devoxx4Kids chapter in the US and continues to promote technology education among children. An author of several books on technology, an avid runner, a globe trotter, a Java Champion, a JUG leader, NetBeans Dream Team member, and a Docker Captain, he is easily accessible at @arungupta.

Developers have been using containers for optimal management and deployment of applications for a long time, and by using containers, they run applications along with their dependencies in an independent and single environment (containers) in different environments from production to development and they separate the software from the infrastructure of the host environment. Linux was one of the operating systems that supported containers well, we talked about how to install Docker in Linux in previous articles. Still, today Windows also supports Docker containers in its new versions and tries to respond to the needs of developers. Windows containers can manage and run modern programs based on the Net core in addition to traditional Windows programs.

In addition, Windows introduced support for Kubernetes in Windows Server to attract developers’ satisfaction so that developers can benefit from Kubernetes features for deploying and managing containers on Windows. Docker is an open-source platform for managing, running, transporting, and creating applications in independent container environments. It allows you to package applications, settings, and required services in a separate unit called a container so that programs with different settings can run in the same environment without interfering with each other or the operating system.

This article will teach how to configure and run Docker in Windows Server 2016, 2019, and 2022. To use Docker features on Windows Server to create, run and deploy applications with the help of containers, read this article to the end.

Familiarity with Docker

Dockers are standard components for integrating operating system libraries with application source code and application dependencies for code execution. In other words, Docker is a popular open-source platform for running, creating, managing, deploying, and updating applications in independent and portable container environments.

Using Docker, services, and applications are packaged in containers and can be used in a portable way. Docker allows transporting containers and programs between systems so that you can run programs with their dependencies in any environment.

Docker separates containers from the host environment and turns them into an independent environment to prevent programs from interfering with each other or with the operating system, thanks to the isolation it creates. The most common use of containers is in organizations with hybrid multi-cloud environments with the purpose of development because the development and delivery of distributed applications are facilitated and optimized with the help of the features of containers. We have already discussed in detail what Docker is, if you need more information to understand better about Docker, you can read our previous article.

Steps to install Docker on Windows Server

If you want to use Docker on Windows Server, you must purchase a Windows VPS running Windows Server 2016 or later because Windows does not support Docker in versions older than 2016. You must also have administrative privileges to install and configure the server.

Ensure Intel VT-x or AMD-V virtualization technology is enabled in BIOS settings, and also enable Hyper-V in your system because Docker uses Hyper-V to run containers on Windows Server.

Before installing Docker, for optimal use of Docker, download and install the Docker Desktop program from the Docker website on Windows Server. Now you can start installing and configuring Docker on Windows Server. You can install Docker on Windows Server using the Windows graphical environment and the Powershell tool. We teach both methods so you can install Docker on Windows Server with whichever method is more convenient.

Method 1: Docker installation on Windows Server via Powershell

After making sure that you have administrative privileges, you can start the Docker installation process on Windows Server by using the commands and capabilities of the Powershell tool:

1. Enable the Container’s Feature

Enter windows powershell and start installing Docker in Windows Server by enabling the container features because in Windows, container features are not enabled by default, and you are responsible for enabling the container features. Run the following command for this purpose:

Enable-WindowsOptionalFeature -Online -FeatureName Containers

2. Docker installation

After enabling the containers feature on the Windows server, install the latest version of the docker engine and docker repositories by running the following commands:

Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider

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.

After installing the required Docker repositories and packages, restart the Windows server using the following command:

Restart-Computer -Force

3. Verify the Docker Installation

After the Windows server is started, run the following command in Powershell to make sure that Docker is installed on the Windows server by checking the installed Docker version:

Get-Package -Name Docker -ProviderName DockerMsftProvider
Output:
Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
docker                         20.10.9          DockerDefault                    DockerMsftProvider

To check the Docker version on Windows Server, you can use the following command instead of the previous one:

docker version

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

To access more information about Docker, you can type the following command:

docker info

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: 4
Total Memory: 8GiB
Name: tc-win56
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

Method2: Configuring Docker on Windows Server via GUI

Many Windows users prefer Windows to other operating systems because of its graphical user interface. They run away from the Linux terminal environment and take refuge in the familiar and simple GUI of Windows. Therefore, installing Docker in the graphical user interface of Windows Server may be easier for many users; for this reason, we will teach how to install Docker in Windows Server by GUI.

1. launch the server manager and run the Add Roles and Features Wizard.

ihow to install docker on windows server

2. From the “Installation Type” tab, select the “Role-based” option and specify your server as the destination.

how to configure docker on windows server

3. Go to the “Server Roles” tab and click Next.

how o configure docker on windows server

4. In the “Features” tab, check the checkbox next to “Containers” and continue.

how to configure and run docker on windows server

5. Go to the “Confirmation” tab and confirm the installation of the containers.

how to configure docker on windows

After completing the container installation process, you will be asked to reboot the Windows server.

After restarting the system, you can see Docker Engine in the services section.

Running and using Docker on Windows Server

Now that you have installed Docker on Windows Server, it’s time to familiarize yourself with useful Docker commands to run, manage, create Docker containers, and use Docker’s capabilities effectively. In the following, we provide a useful guide for running and using Docker so that you can easily use the features of Docker in Windows Server for various purposes.

Basic commands for managing containers in Docker

To specify a new name for launching a new container, use the-nameoption with Docker:

docker.exe container run --name [new container name][ Special images name]

The-doption is used together with Docker to run the container in detached mode:

docker.exe container run -d [ Special images name]

For example:

docker.exe container run -d debian:latest

To run the container in interactive mode, the-itoption is used along with Docker:

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

Check the status of containers after starting by running the following command:

docker.exe ps -a

The main syntax for starting the docker container is as follows:

docker container start container-name

The main syntax for stopping the docker container is as follows:

docker container stop container-name

Remove the docker container using the following command:

docker container rm container-name

How to run Docker Container

To run the Docker Container, first launch the Docker service using the following command:

Start-Service Docker

Then download the Docker dotnet nano server container image:

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

After you have downloaded the image, which is a prerequisite for running the container, you can run the container using the downloaded image by using the following command:

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

You can also start an interactive session in the container using the following command:

docker run -it mcr.microsoft.com/windows/servercore:ltsc2022 powershell

To exit the session, run the following command:

exit

How to run Docker Container by preserving their data

Creating and using Persistent Storage, a dedicated directory or Docker volume specified for a specific path, helps you run Docker Container while keeping Docker Container data. To create Persistent Storage for container data, you need to create a path:

mkdir C:\docker-container-storage

Test the write permission on it using the following command:

Write-Output 'Docker Persistent Storage Test' | Out-File -Encoding default C:\docker-container-storage\index.html

To spin and map the container that was made from the storage space and map the contents of C:\disk01 in the container to your system’s C:\docker-container-storage, use the following command:

docker run -it -v C:\docker-container-storage:C:\disk01mcr.microsoft.com/windows/servercore:ltsc2022

How to run Linux Container on Windows Server

Since Windows Server supports running Windows containers by default, what should we do to run Linux Containers? Fortunately, this problem also has its solution. You can run Linux Containers using Docker Enterprise Edition Preview, which supports running Linux containers by providing a LinuxKit system.

To run a Linux Container, the first step is to remove the Windows Docker engine and install Docker for Linux:

Uninstall-Package -Name docker -ProviderName DockerMSFTProvider
Install-Module DockerProvider
Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview

Then enable the LinuxKit system to run Linux containers:

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

Start the Docker service:

Restart-Service docker

To run the Linux container, enter the following command to download the latest Ubuntu container image, create the container based on it, and connect it to the container shell:

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

The previous command is executed for the Ubuntu container. To verify the Ubuntu version, you should now add the following commands in the newly created container:

cat /etc/os-release

Output:

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

How to build Docker Images

DockerFiles are usually used to create Docker Images, so creating Docker Images requires creating a DockerFile. For this purpose, you must first create a special directory for DockerFile using the following commands:

mkdir docker-file
cd docker-file

We will use an example for better understanding. For example, create a Custom Dockerfile for the IIs test:

$str_file = @"
FROM mcr.microsoft.com/windows/servercore:ltsc2022
MAINTAINER  OperaVPS.com
RUN dism.exe /online /enable-feature /all /featurename: iistest /NoRestart
RUN echo Dockerfile test example > C:\inetpub\wwwroot\index.html
EXPOSE 80
CMD [ "cmd" ]

Export the desired values to the file by running the following command:

$str_file | Out-File Dockerfile -Encoding Default

Then run the following command to build the docker image:

docker build . -t iistest:latest

After a while, creating the custom Docker container will be finished, and you will successfully create the iistest Docker Images. Using this test, you can spin a new container. Since we’ve built our new IIs Docker container image, we can now use that container image to spin up an actual IIs container that contains the customizations added using the docker file as well as the files we want.

How to pull Windows Container image for Docker

Run the following command to pull the Windows container image for Docker:

docker pull [image-name]

Or

docker pull mcr.microsoft.com/windows/servercore:ltsc2022

The Docker Network Management Guide

With the help of Docker features, you can manage networks in Docker, that is, control the communication of containers in Docker with each other and the outside world. In the following, we will introduce several commands for managing networks in Docker:

  • Viewing available networks in Docker:
docker network ls
  • Get more information about a specific network:
docker network inspect [network name]
  • Connecting the container to your desired network:
docker network connect [network name] [container name]
  • Create a new network using the NAT driver( because the containers are connected to the NAT network by default):
docker network create [network name] -d "nat"
  • Remove network:
docker network rm [network name]
  • Delete all the networks to which the container is not connected:
docker network prune

FAQ

  • Processor: 64-bit processor
  • RAM: 4GB
  • BIOS settings: enable Intel VT-x or AMD-V virtualization technology in BIOS settings
  • Operating System: You need Windows Server 2016 or later to run Docker.

Container images are executable, lightweight, and portable software packages that include all the requirements needed to run the program, such as code, system tools, dependencies, and libraries. Container images are known as containerization technology’s building blocks.

By default, Windows Server only runs Windows containers. Still, Docker in Windows server also supports running Linux containers. Docker in a Windows servers by using a lightweight Linux virtual machine makes it possible to run Linux containers alongside Windows containers.

Docker creates an environment to speed up the development cycle and run applications in an isolated environment. Docker allows you to run your applications in different environments, including production, development, testing, and building portable applications. Docker containers consume less resources than virtual machines.

Wrapping Up

Docker is an efficient tool for developers for fast and scalable development. Docker capabilities significantly accelerate the provisioning and deployment of applications. Because it plays an effective role in the speed of deploying, sending, and testing program codes and also improves the management of docker containers. Therefore, using Docker is an advantage for developers in enhancing and accelerating the development cycle.

In addition, Windows Server provides a secure and efficient platform for developers by supporting Docker and its features. Windows provides features like Hyper V isolation and the possibility of running Windows and Linux containers to satisfy developers.

In this article, we taught how to install Docker in Windows Server 2016, 2019, and 2022 using PowerShell and GUI. We also taught useful commands to improve the management of Docker containers so that you can enjoy Docker’s capabilities.

If you have any questions about Docker, ask us in the comment section so we can help you as soon as possible.

We hope you enjoyed reading this article.

  • Docker add user to docker group windows
  • Docker compose volumes windows 10
  • Dock windows как в mac os для windows
  • Doc panel для windows 10
  • Doc opener скачать бесплатно windows 10