Next in this article How to Install and Run Docker on Windows Server 2016, 2019, 2022 is to introduce Docker.
What Is Docker?
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:
- 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.
- 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.
- 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.
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
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install Docker Engine
Install-Package -Name docker -ProviderName DockerMsftProvider
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 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
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
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:
docker run -it --rm ubuntu /bin/bash
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:
How to Use Docker
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
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
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.