Docker desktop for windows server 2019

В нашем справочнике есть мануал по установке Docker на сервере, работающем под управлением Ubuntu 20.04. Настоящая же статья посвящена тому, как запустить хранилище Docker на операционной системе Windows Server 2019.

На виртуальном сервере, работающем под управлением Windows Server 2019, производить установку Docker наиболее оптимально при помощи интегрированной среды PowerShell. Запустить PowerShell можно из командной строки, используя команду powershell, либо из оболочки Server Manager – ToolsWindows PowerShell.

Установка Docker

Первым шагом необходимо будет установить функцию контейнеров. Сделать это можно при помощи следующей команды:

Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

Далее нужно установить сам Docker, для чего используйте следующую инструкцию:

Install-Package -Name docker -ProviderName DockerMsftProvider

Во время инсталляции система попросит вашего согласия на установку пакета. Для продолжения установки нужно нажать Y.

Установка Docker

Следующей командой необходимо перезагрузить сервер по окончании установки Docker:

Restart-Computer -Force

Проверить версию установленного пакета можно при помощи команды:

Get-Package -Name Docker -ProviderName DockerMsftProvider
Версия Docker

Для этого также можно использовать следующую команду:

docker version

Теперь необходимо запустить Docker:

Start-Service Docker

Запуск контейнера

После чего уже можно будет загрузить и установить базовый образ контейнера. Например, следующей командой вы сможете произвести загрузку базового образа Nano Server для Windows Server 2019:

docker pull mcr.microsoft.com/windows/nanoserver:ltsc2019
Загрузка образа mcr.microsoft.com/windows/nanoserver:ltsc2019

Список установленных образов можно вывести при помощи команды:

docker images
Список установленных образов - Установка Docker на Windows Server 2019

Теперь можно приступить к созданию образа. Команды, при помощи которых создаются и запускаются образы, лучше выполнять в командной строке, запущенной от имени администратора. Использование интегрированной среды Windows PowerShell не позволяет работать с контейнерами, так как контейнеры в конечном итоге перестают отвечать на запросы.

Запуск загруженного контейнера Nano Server с интерактивным сеансом производится следующей командой:

docker run -it mcr.microsoft.com/windows/nanoserver:ltsc2019 cmd.exe

В качестве примера на диске C:\ запущенного контейнера создайте каталог TEMP:

mkdir C:\TEMP

Перейдите в созданный каталог и создайте файл my_file.txt, содержащий текст My File:

cd C:\TEMP
echo "My File" > my_file.txt

После чего выйдите из контейнера:

exit

Следующая команда нужна будет для получения идентификатора контейнера, из которого вы только что вышли:

docker ps -a
Получение идентификатора контейнера

В нашем примере идентификатор контейнера выглядит как 722200a246df. Исходя из этого вы можете создать новый образ, в котором будут учитываться изменения, внесённые в изначальный образ. Для этого нужно будет использовать команду docker commit. Новый образ мы назовём my_container, поэтому команда для его создания будет выглядеть следующим образом:

docker commit 722200a246df my_container

При помощи команды docker images можно вывести список образов, в котором будет присутствовать новый образ:

Список образов

Теперь вы можете запустить созданный контейнер при помощи команды docker run. Использование параметра --rm позволяет удалить запущенный контейнер после завершения работы оболочки командной строки. В нашем примере мы запустим контейнер my_container и выведем содержимое файла my_file.txt из директории TEMP на диске C:\.

docker run --rm my_container cmd.exe /s /c type C:\TEMP\my_file.txt
Запуск контейнера - Установка Docker на Windows Server 2019

В итоге Docker создаст контейнер из образа my_container, запустит экземпляр командной строки, в которой выведет содержимое файла C:\TEMP\my_file.txt, после чего Docker остановит работу контейнера и удалит его.

Installing-the-MsftDockerProvider-and-Docker

Installing-the-MsftDockerProvider-and-Docker

Want to play around with Windows Server Docker Containers? This is easy to do with only a few steps on a Windows Server 2019 host. Additionally, you may want to do more than play around. You may have a containerized application you want to deploy and run on a Windows Server container host. This post will look at how to install Docker in Windows Server 2019 and get an overview of the step-by-step approach to running containerized applications on your Windows Server 2019 hosts.

Modernized Windows applications with Windows Server and Docker

There is no question that businesses are looking to modernize their applications to be cloud native and run microservices instead of the traditional monolithic 3-tier legacy server applications. Native Docker containers on Windows Server and Windows Desktops provides many different use cases in your Windows environment. These include:

  • Containerized Windows apps – You might envision Docker being a more Linux native solution. However, Microsoft and Docker run and work well together due to a joint partnership between Docker and Microsoft. With the native Windows integration from Docker, developers can leverage Docker containers the same way that they do on Linux, using the same Docker CLI, API, and image format. There are additional benefits to running Docker containers in Windows, including Hyper-V isolation that provides an extra layer of security to your container instances. Microsoft also continues to reduce the size of the Windows Server Core and other Windows images for use with Docker, making the footprint even smaller.
  • Run both Windows and Linux nodes on the same cluster – Using Docker enterprise, organizations can run both Windows Server and Linux nodes on the same cluster. Hybrid applications may leverage both Linux and Windows components. With Docker Enterprise, Windows containers have access to the same features as Linux containers
Running-both-Linux-and-Windows-containers-in-the-same-cluster-1

Running both Linux and Windows containers in the same cluster
  • Modernize legacy Windows Server apps – Cobine Docker Enterprise platform with built-in tools to containerize legacy Windows applications.

Let’s take a look at the steps required to install docker in Windows Server 2019. This includes a few steps that need to be taken to get the containers feature enabled as well as installing Docker and the container images. Let’s look at the following steps.

  1. Install Windows Server 2019 containers feature
  2. Install Hyper-V
  3. Install DockerMsftProvider and latest Docker version
  4. Pull Docker images
  5. Run a Docker image

1. Install Windows Server 2019 Containers feature

First, before running Docker images, we need to install the Windows Server 2019 containers feature. This installs and configures your Windows Server 2019 host for use with containerized workloads. This can easily be done using the Server Manager tool. Under Features, install Containers.

Install-the-containers-feature-in-Windows-Server-2019

Install the containers feature in Windows Server 2019

You will need to reboot after the feature installation, or optionally select to reboot automatically after the feature is installed.

Finishing-the-containers-feature-installation-with-a-reboot

Finishing the containers feature installation with a reboot

2. Install Hyper-V

If you plan to use Hyper-V isolation with your Docker containers (which I highly recommend for extra security), you will need to install the Hyper-V role. This is located under Server Roles > Hyper-V.

Enabling-Hyper-V-for-Hyper-V-isolation-for-Docker-containers

Enabling Hyper-V for Hyper-V isolation for Docker containers

You can also easily install Hyper-V using PowerShell with the following command:

Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
Installing-the-Hyper-V-role-using-PowerShell-for-Hyper-V-isolation

Installing the Hyper-V role using PowerShell for Hyper-V isolation

3. Install DockerMsftProvider and latest Docker version

Next, we need to install DockerMsftProvider and the latest Docker version on our Windows Server 2019 host. To do this, run the following commands. To install the DockerMsftProvider, use:

Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

Now, to install Docker:

Install-Package -Name docker -ProviderName DockerMsftProvider

After you have ran the above commands, reboot your Windows Server 2019 server. To use PowerShell, run the following:

Restart-Computer -force
Installing-the-MsftDockerProvider-and-Docker-1

Installing the MsftDockerProvider and Docker

4. Pull Docker Images

Let’s now look at pulling Docker images. This is straightforward and can be done from a PowerShell command line. To pull the LTSC Windows Server 2019 core image, use the following command:

docker pull mcr.microsoft.com/windows/servercore:ltsc2019
Downloading-and-extracting-a-Windows-Server-2019-Docker-image

Downloading and extracting a Windows Server 2019 Docker image

5. Run a Docker Image

To run a Docker image, we can do this using the following command. This will spin up a container to run a simple command.

docker run -it mcr.microsoft.com/windows/servercore:ltsc2019 hostname

If you want to run the container interactively, you will use the following command:

docker run -it mcr.microsoft.com/windows/servercore:ltsc2019
Interactive-Docker-image-running-and-listing-Docker-containers

Interactive Docker image running and listing Docker containers

Windows Docker Container Hyper-V Isolation

Windows Server 2019 Hyper-V isolation allows effectively running a container with boundaries so that the only kernel the container knows about is the Hyper-V VM container that it is provisioned inside of. This allows running multiple containers with a much higher degree of security when compared to running native Windows containers without the isolation so that the host’s kernel is shared between all running containers.

From Microsoft regarding the Hyper-V isolation mode:

This isolation mode offers enhanced security and broader compatibility between host and container versions. With Hyper-V isolation, multiple container instances run concurrently on a host; However, each container runs inside of a highly optimized virtual machine and effectively gets its own kernel. The presence of the virtual machine provides hardware-level isolation between each container as well as the container host.

Hyper-V-isolation-architecture-overview

Hyper-V isolation architecture overview
docker run -it --isolation=hyperv mcr.microsoft.com/windows/servercore:ltsc2019

Verifying Windows Server 2019 Docker Container Hyper-V Isolation

Using the command we can verify the Windows Server 2019 Docker Image Hyper-V isolation. Use the command below:

get-process -Name vmwp
Verifying-Windows-Server-2019-Hyper-V-container-isolation

Verifying Windows Server 2019 Hyper-V container isolation

Wrapping Up

The process to Install Docker in Windows Server 2019 is fairly straightforward to get Docker up and running. Windows Server 2019 provides many great features to run your Docker containers, including Hyper-V isolation for additional security and kernel protection. Also, Microsoft Windows Server 2019 can run both Windows and Linux containers meaning you can have a mixed environment supporting applications needing both Windows and Linux components. With each new Windows release including semi-channel releases, Microsoft is continuing to minimize the footprint of the Windows Docker images. These are getting smaller and more efficient.

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don’t have to.

September 22, 2022
PHP
  • Install Docker on Windows Server 2019
  • Install Docker Desktop on Windows
  • Docker Engine on Windows

Install Docker on Windows Server 2019

The process for installing Docker EE on Windows Server is quite simple with
the introduction of the OneGet provider PowerShell Module. As a first step,
install the Docker-Microsoft PackageManagement Provider module from the
PowerShell Gallery. Install-Module -Name DockerMsftProvider -Repository
PSGallery -Force.

Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart


Install-WindowsFeature containers -Restart


Install-Module -Name DockerMsftProvider -Repository PSGallery -Force


Get-PackageProvider -ListAvailableget-packagesource -ProviderName DockerMsftProvider


Install-Package -Name docker -ProviderName DockerMsftProvider


Start-Service Docker


docker network ls


docker version


winver


docker image pull mcr.microsoft.com/windows/nanoserver:1809


docker image ls


docker container run mcr.microsoft.com/windows/nanoserver:1809 hostname


docker container ls -a

Install Docker Desktop on Windows

Docker only supports Docker Desktop on Windows for those versions of Windows
10 that are still within Microsoft’s servicing timeline. Windows Server 2016
and Windows Server 2019. It shows you how to use a MusicStore application with
Windows containers. Docker Container Platform for Windows articles and blog
posts on the Docker website. Note.

"Docker Desktop Installer.exe" install



Start-Process '.\win\build\Docker Desktop Installer.exe' -Wait install



start /w "" "Docker Desktop Installer.exe" install



net localgroup docker-users <user> /add

Docker Engine on Windows

Applies to: Windows Server 2022, Windows Server 2019, Windows Server 2016. The
Docker Engine and client aren’t included with Windows and need to be installed
and configured individually. Furthermore, the Docker Engine can accept many
custom configurations. Some examples include configuring how the daemon
accepts incoming requests, default

{
    "authorization-plugins": [],
    "dns": [],
    "dns-opts": [],
    "dns-search": [],
    "exec-opts": [],
    "storage-driver": "",
    "storage-opts": [],
    "labels": [],
    "log-driver": "",
    "mtu": 0,
    "pidfile": "",
    "data-root": "",
    "cluster-store": "",
    "cluster-advertise": "",
    "debug": true,
    "hosts": [],
    "log-level": "",
    "tlsverify": true,
    "tlscacert": "",
    "tlscert": "",
    "tlskey": "",
    "group": "",
    "default-ulimits": {},
    "bridge": "",
    "fixed-cidr": "",
    "raw-logs": false,
    "registry-mirrors": [],
    "insecure-registries": [],
    "disable-legacy-registry": false
}



{
    "hosts": ["tcp://0.0.0.0:2375"]
}



{   
    "data-root": "d:\\docker"
}



{
    "hosts": ["tcp://0.0.0.0:2376", "npipe://"],
    "tlsverify": true,
    "tlscacert": "C:\\ProgramData\\docker\\certs.d\\ca.pem",
    "tlscert": "C:\\ProgramData\\docker\\certs.d\\server-cert.pem",
    "tlskey": "C:\\ProgramData\\docker\\certs.d\\server-key.pem",
}



sc config docker binpath= "\"C:\Program Files\docker\dockerd.exe\" --run-service -H tcp://0.0.0.0:2375"



{
    "bridge" : "none"
}



{
    "group" : "docker"
}



[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://username:[email protected]:port/", [EnvironmentVariableTarget]::Machine)



Restart-Service docker



# Leave swarm mode (this will automatically stop and remove services and overlay networks)
docker swarm leave --force

# Stop all running containers
docker ps --quiet | ForEach-Object {docker stop $_}



docker system prune --volumes --all



Uninstall-Package -Name docker -ProviderName DockerMsftProvider
Uninstall-Module -Name DockerMsftProvider



Get-HNSNetwork | Remove-HNSNetwork



Get-ContainerNetwork | Remove-ContainerNetwork



Remove-Item "C:\ProgramData\Docker" -Recurse



Remove-WindowsFeature Containers
Remove-WindowsFeature Hyper-V



Restart-Computer -Force

Installing/configuring Docker for an environment that is not explicitly mentioned on the Docker Desktop website.

Due to the fact that the CM-Connect is native to the Linux environment, it will need help with running outside of it. This is the reason that we utilize Docker containers. Docker allows for our software to run as expected in any operating system. Windows has many OS versions and you will find that the Docker Desktop website only offers instructions on the latest. However, Docker is compatible with Windows Server 2019. There are just a few requirements needed from the server.

First, you will need to make sure that Nested Virtualization is enabled. this will allow you to run Hyper-V inside of the server. Hyper-V also needs to be enabled.

hyper-vexample

After this process is completed, the server must be restarted.

Now you can download and install Docker Desktop for windows. You can find it here: Docker for Windows. 

Once Docker is installed, be sure to open Docker, navigate to the settings, and complete the following:

  1. In the General tab, select Hyper-V from the Use the WSL 2 based engine dropdown.
  2. Click Apply & Restart to apply the changes and restart Docker Desktop.

After restart and the bottom left corner of Docker Desktop is green, Docker is ready to use.

Windows Server 2019 is the next long-term support release of Windows Server, and it’s available now! It comes with some very useful improvements to running Docker Windows containers — which Docker Captain Stefan Scherer has already summarized in his blog post What’s new for Docker on Windows Server 2019.

UPDATE: the second edition of my book Docker on Windows is out now. It focuses entirely on Windows Server 2019

You need Windows Server to run “pure” Docker containers, where the container process runs directly on the host OS. You can use the same Docker images, the same Dockerfiles and the same docker commands on Windows 10, but there’s an additional virtualization overhead, so it’s good to use a Windows Server VM for test environments.

On Windows 10 Docker Desktop is the easiest way to get started

If you want to check out the newest version of Windows Server and get running Docker containers, here’s what you need to do.

Get Windows Server 2019

You can download the ISO to install Windows Server 2019 now, from your Visual Studio subscription if you have one, or a 180-day evaluation version if you don’t. VMs with Windows Server 2019 already deployed will be available on Azure shortly.

The installation procedure for 2019 is the same as previous Windows Server versions — boot a VM from the ISO and the setup starts. I prefer the core installation with no GUI:

Installing Windows Server 2019 Core

I installed Server 2019 onto a Hyper-V VM running on my Windows 10 machine, with the VM disks stored on an external SSD drive. The setup finished in a few minutes, and it runs very quickly — even with just 4GB RAM allocated.

You can also upgrade from previous Windows Server versions to 2019 using the ISO.

Connect to the Server

When you RDP into a Windows Server Core machine you just see a command prompt. The first time you connect you’ll need to set the password for the default Administrator account. Then I like to set PowerShell as the default command shell, so whenever you RDP you get into a PowerShell session:

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -name Shell -Value 'PowerShell.exe -noExit'

Configure Windows Features

To run containers you need to enable the Containers feature, and for a non-production VM I also disable Windows Defender to stop it burning CPU cycles. You’ll need to reboot after these steps:

Install-WindowsFeature -Name Containers

Uninstall-WindowsFeature Windows-Defender

Restart-Computer -Force

Configure Windows Updates

You’ll want to make sure you have the latest updates, but then I disable automatic updates so I only get future updates when I want them. There’s no GUI in Windows Server Core, so run sconfig and then select:

option 5, to set Windows Updates to manual

option 7, to enable Remote Desktop Access to the server

option 6, to download and install all updates

Then you’re ready to install Docker.

Install Docker on Window Server 2019

Windows Server licensing includes the licence cost for Docker Enterprise, so you can run the enterprise edition with production support for containers from Microsoft and Docker.

The latest Docker Enterprise engine is version 19.03 18.03, which you can explicitly install with PowerShell:

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

This sets up Docker as a Windows Service, which you need to start:

Pull the Windows Base Images

Any Docker containers you run on Windows Server 2019 will be based on Windows Server Core or Nano Server. You’ll need both those images, and be aware that the base images are now hosted on Microsoft’s container registry, MCR:

docker image pull mcr.microsoft.com/windows/servercore:ltsc2019

docker image pull mcr.microsoft.com/windows/nanoserver:1809

These images are tiny compared to the Windows Server 2016 versions. Windows Server Core has shrunk from over 10GB to a 1.5GB download, and Nano Server has shrunk from over 1GB to a 90MB download!

[Optional] Pull the .NET Core Images

The .NET Core team released versions of their SDK and runtime images as soon as Windows Server 2019 launched. You can pull those now and start running your .NET Core apps in 2019 (there are also .NET Framework SDK and ASP.NET images available — hopefully SQL Server will get some attention soon…)

docker image pull mcr.microsoft.com/dotnet/core/aspnet:3.0

docker image pull mcr.microsoft.com/dotnet/core/sdk:3.0.100

The upstream Docker images are still listed on Docker Hub, so that’s where you go for discovery — but they get served from Microsoft’s own image registry, MCR.

Try it Out!

I’ve pushed an updated version of my .NET Core whoami image, so you can try out ASP.NET Core 3.0 running in Windows Server Core 2019 containers:

docker container run -d -p 8080:80 sixeyed/whoami-dotnet:3.0

One of the enhancements for Docker in Windows Server 2019 is that loopback addresses now work, so you can visit this container using localhost on the server, and using the same published port from an external machine:

Published ports now do loopback

And in Swarm Mode…

I’ll post a longer explanation of what you can do with Docker in Windows Server 2019 that you couldn’t do in Windows Server 2016, but here’s just one other thing: Windows Server 2019 now supports ingress networking for Docker swarm mode. That means you can run multiple containers on one server, all listening on the same port, and Docker will load-balance incoming requests between the containers.

I have lots more detail on this in my Pluralsight course Managing Load Balancing and Scale in Docker Swarm Mode Clusters

Switch your server to a single-node swarm:

docker swarm init --advertise-addr 127.0.0.1

Now deploy the whoami app as a swarm service, with multiple replicas and a published port:

docker service create `
  --publish 8070:80 `
  --replicas 5 `
  sixeyed/whoami-dotnet:nanoserver-1809

Now when you browse to the VM from outside, Docker will load-balance requests across the five containers which are hosting the service:

whoami in swarm mode

There’s More

Windows Server 2019 is an evolution to the container functionality you get with Docker. Windows Server 2016 is still perfectly fine for production, but 2019 brings Windows containers much closer to feature parity with Linux containers, and smooths over some things which are tricky in 2016.

And the next big thing is Windows support in Kubernetes, which is expected to GA before the end of the year :) went GA this year. Windows containers are now supported in mixed Linux-Windows Kubernetes clusters — find out more from my post Getting Started with Kubernetes on Windows.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Как убрать блокировку файлов в windows 10
  • Как поменять имя пользователя на windows 10 cmd
  • Загрузочная флешка windows 7 с acronis true image
  • Какого типа окон не существует в ос windows
  • Запуск windows под андроид