Рассмотрим установку Docker Desktop for Windows — это Community-версия Docker для систем Microsoft Windows.
Системные требования
- Windows 10 64-bit: Pro, Enterprise, Education (Build 16299 или выше).
Для успешного запуска Client Hyper-V в Windows 10 требуются следующие предварительные требования к оборудованию:
- 64 bit процессор c поддержкой Second Level Address Translation (SLAT).
- 4GB системной памяти.
- Поддержка аппаратной виртуализации на уровне BIOS должна быть включена в настройках BIOS.
Подготовка
Включаем функции Hyper-V Containers Window. Для этого переходим в панель управления — установка и удаление программ — включение или отключение компонентов Windows. Активируем пункт Hyper-V, который включает Hyper-V Managment Tools, Hyper-V Platform.
Также это можно выполнить через powershell или dism (все команды необходимо выполнять с правами администратора).
Powershell:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
DISM:
DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V
Установка
Скачиваем установщик Docker (Docker Desktop Installer) с Docker Hub.
Установка Docker Desktop включает Docker Engine, Docker CLI client, Docker Compose, Notary, Kubernetes и Credential Helper. Контейнеры и образы, созданные с помощью Docker Desktop, используются всеми учетными записями пользователей на компьютерах, на которых он установлен. Это связано с тем, что все учетные записи Windows используют одну и ту же виртуальную машину для создания и запуска контейнеров. При использовании Docker Desktop WSL 2 невозможно обмениваться контейнерами и образами между учетными записями пользователей.
Запускаем установщик Docker Desktop Installer.exe и ожидаем пока он скачает все необходимые компоненты.
После установки система потребует перезагрузки. Перезагружаемся и входим в систему.
После входа может возникнут запрос на установку дополнительного компонента WSL2. Переходим по ссылке и скачиваем необходимый пакет с официального сайта Microsoft.
После скачивания выполняем установку WSL2, после которой снова потребуется перезагрузка.
Настройка и запуск приложения
Входим в систему и ждем запуска всех служб Docker. Когда все службы будут запущены, мы увидим в трее классический значок Docker — это значит что служба установлена и запущена. Далее можно запустить приложение Docker desktop. Далее можно изменить настройки Docker при необходимости:
Рисунок 1 — Изменение параметров Docker desktop
Далее управление Docker выполняется через Powershell. Проверяем версию и выполняем тестовый запуск контейнера:
Рисунок 2 — Проверка версии Docker
После выполнения всех этих действий, Docker готов к использованию.
Нужна помощь? Настройки docker/docker swarm/docker compose мы осуществляем в рамках услуги DevOps-аутсорсинг.
~6 min read
In this post, I describe how to install WSL 2 to serve as the backend for Docker Desktop for Windows. Previously I’ve always worked with Linux in a Virtual Machine using something like VMWare or Virtual Box, but I decided to give Docker Desktop a try, and was pleasantly surprised by the experience!
I’ll start by describing how to install WSL 2 based on the install documents, then show how to install Docker Desktop. Finally, I show the the experience of running a container and how it looks in Docker Desktop.
Installing WSL2
The Windows Subsystem for Linux (WSL) is a way to run a full Linux environment on your Windows machine, without having to install a «heavier» virtual machine, such as Virtual Box, VM Ware, or Hyper-V. WSL 2 also provides a mechanism for running Docker (with Linux containers) on your Windows machine. We’ll install it as a prerequisite for Docker Desktop for Windows.
If you’re running Windows Home, WSL 2 is the only way to run Docker Desktop. On Windows Pro, you can also use Hyper-V, but that is deprecated now, so WSL 2 is the way to go in all cases.
1. Install WSL 1
We’ll start by installing WSL 1 by enabling the WSL feature.
Open PowerShell as Administrator (I hit the Start key, type powershell
and hit ctrl+shift+enter
to open an elevated command prompt). Run the following, to enable WSL 1
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
You should see the following:
> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Deployment Image Servicing and Management tool
Version: 10.0.19041.746
Image Version: 10.0.19042.804
Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.
That enables WSL, but we’re going to enable the newer WSL 2 version, which Docker Desktop can use to run the VM it needs to run containers.
2. Enable the Virtual Machine feature
WSL 2 uses a lightweight VM, so you need to enable the Virtual Machine feature available in Windows 10 version 1903 and higher. In the same, elevated command prompt, run:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
You should see something like the following:
> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Deployment Image Servicing and Management tool
Version: 10.0.19041.746
Image Version: 10.0.19042.804
Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.
3. Restart
Time to restart your machine to ensure everything is registered correctly.
4. Install the WSL 2 update
Download the WSL2 Linux kernel update package for x64 machines and install it.
Note, if you see the following error when running the update, make sure you’ve restarted your machine afer installing the WSL 1 and VM features:
The installer runs very quickly, and hopefully you’ll see a confirmation screen, something like the following:
5. Set WSL 2 as your default version
This is an easy step, just run wsl --set-default-version 2
in any PowerShell window:
>wsl --set-default-version 2
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
6. (Optional) Install a Linux distribution
We actually don’t need to install a Linux distribution to use Docker Desktop, but if you want to shell into Linux directly, you’ll need to install one. You can install a distribution directly from the Microsoft Store.
The first time you launch the distribution, the distribution will extract and install, and you’ll need to set a username and password.
7. (Optional) Add to Windows Terminal
If you’re using Windows Terminal (you should be!) you can configure it to open your WSL distribution. The easiest way to do this is to open up the settings.json file and reset it. You can do this by deleting the contents of the file—Terminal will automatically repopulate it with the defaults, which will include a tab for WSL.
Obviously you won’t want to lose your setting customisations, so make sure to backup the contents of the file first!
You’re looking for WSL in the profiles
list—add that to you profile list, and you’ll be able to quickly open up your WSL instance from Windows Terminal!
That’s the prerequisite starter for Docker Desktop covered, so now lets get to the main course!
Installing Docker Desktop for Windows
1. Download and Install
Head to the Docker Desktop website and download the Installer for Windows.. This is a hefty ~500MB, but once it’s finished, run the installer.
On the first screen, ensure you keep «Install required components for WSL 2» checked:
After clicking OK, the installer will unpack a whole load of files:
Before finally prompting you to log out of your Windows account to complete the installation:
2. Logout and back in
The Docker Desktop installer will automatically log you out of your Windows account on completion. When you sign back in, you’ll get a notification that Docker is starting the Linux Containers WSL 2 backend. Eventually, the main Docker Desktop window will pop up, and offer you a tutorial
3. Give it a try!
With Docker Desktop installed, you now have the docker
command available in your command prompt:
> docker
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
...
Now it’s installed, let’s take it for a spin!
Trying out Docker Desktop for Windows
For simplicity, we’ll run one of the .NET 5.0 sample apps available on DockerHub:
docker run -it --rm `
-p 8000:80 `
--name my-sample `
mcr.microsoft.com/dotnet/samples:aspnetapp
This is a simple Razor Pages app, packaged in a Docker image, and ready to run. You can see the Dockerfile for the app here. When you run the above command Docker will pull the image, run it and start listening:
Unable to find image 'mcr.microsoft.com/dotnet/samples:aspnetapp' locally
aspnetapp: Pulling from dotnet/samples
45b42c59be33: Extracting [=========================> ] 13.57MB/27.1MB
752dcc4c3a04: Download complete
5ccb476d6b8b: Download complete
513626bd05cb: Downloading [======================> ] 472.8kB/1.
...
Status: Downloaded newer image for mcr.microsoft.com/dotnet/samples:aspnetapp
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://[::]:80
If you navigate to http://localhost:8000/, you’ll see the app running there—a Linux container, running on Windows 🤯
The interesting thing, which I didn’t realise until I installed it, is that Docker Desktop for Windows installs a very nice UI for managing your containers!
If you click on the my-sample
container row, you’ll see the logs for the container:
You can also inspect the environment variables, view stats about the container, or click CLI to open a shell inside (exec
into) the container! You can do all these things from the command line obviously, and if you’re automating things, that’s definitely the right option. For casual or local development, personally I find you can’t beat a nice GUI!
Summary
In this post I described how to Install WSL, upgrade it to WSL 2, and how to install Docker Desktop. This requires a restart of Windows and a logout which is a bit annoying, but otherwise it went very smoothly. The Docker Desktop UI also looks very handy, in particular the ability to exec
into a container—I’m always getting the CLI command wrong, so that will be very unseful!
Andrew Lock | .Net Escapades
Want an email when
there’s new posts?
1,600 words, 8-minute read
Docker can be installed on Linux, mac OS, or Windows.
Requirements and installation instructions can be found on the Docker Docs help pages.
Install Docker on Linux #
Docker Desktop for Linux can be downloaded from Docker Hub. The installer includes the Docker server, CLI, Docker Compose, Docker Swarm, and Kubernetes.
Alternatively, the Docker command-line tool is available in official Linux repositories although these are often older editions. The latest edition is supported on recent 64-bit editions of popular Linux distros:
- Ubuntu (and derivatives such as Mint)
- CentOS
- Debian
- Fedora
Static binaries are available for other distros, although Googling “install Docker on [your OS]” may provide easier instructions, e.g. “install Docker on a Raspberry Pi”.
Follow the Docker documentation for your distro. For example, Docker for Ubuntu is installed with the following commands:
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
To run Docker commands as a non-root user (without sudo
), create and add yourself to a docker
group:
sudo groupadd docker
sudo usermod -aG docker $USER
Then reboot to apply all changes.
Install Docker on macOS #
Docker Desktop for macOS Sierra 10.13 and above can be downloaded from Docker Hub. The package includes the Docker server, CLI, Docker Compose, Docker Swarm, and Kubernetes.
Two editions are available: stable and edge with experimental features. The stable version is best for most developers.
Double-click Docker.dmg
to open the installer, then drag the Docker icon to the Applications folder. Double-click Docker.app in that folder to launch Docker.
After completion, the whale icon in the status bar indicates Docker is running and commands can be entered in the terminal.
Install Docker on Windows #
Docker Desktop for Windows requires either WSL2 or Hyper-V.
Windows Subsystem for Linux (WSL) 2 #
WSL allows you to run full Linux environments directly on Windows 10 or Windows 11.
IMPORTANT!
You can not install the Linux edition of Docker within a WSL-powered Linux distro. You must install Docker Desktop for Windows which allows Docker commands to be run in all Windows and Linux terminals.
WSL2 is the recommended default option for Docker on Windows. It is faster than Hyper-V and available in all editions of Windows 11 and Windows 10 from the May 2020 update (version 2004, OS build 19041).
To install WSL2:
-
Enable hardware virtualization support in your BIOS.
This will be active on most devices, but check by rebooting and accessing your PC’s BIOS panels – typically by hitting DEL, F2, or F10 as your system starts. Look for Virtualization Technology, VTx or similar options. Ensure they are enabled, save, and reboot.
WARNING! Be careful when changing BIOS settings – one wrong move could trash your PC.
-
Enable the Virtual Machine Platform and Windows Subsystem for Linux options in the Turn Windows features on or off panel:
This can be accessed by hitting the Start button and typing the panel name or from Programs and Features in the classic Control Panel.
-
Reboot, then enter the following command in a Windows Powershell or
cmd
prompt to set WSL2 as the default:wsl --set-default-version 2
-
Download and install your preferred distro by searching for “Linux” in the Microsoft Store app. Ubuntu is a good choice.
-
To complete the installation, launch your distro by clicking its Store’s Launch button or choosing its icon from the Start menu.
You may be prompted to install a kernel update – follow the instructions and launch the distro again.
-
Enter a Linux username and password. These are separate from your Windows credentials although choosing the same ones can be practical.
-
Ensure your distro is up-to-date. For example, on an Ubuntu bash prompt enter:
sudo apt update && sudo apt upgrade
You can now install Docker Desktop (see below). For the best performance and stability, store development files in your Linux file system and run Docker from your Linux terminal.
More information about installing and using WSL2:
- Windows Subsystem for Linux 2: The Complete Guide, and
- optionally, Windows Terminal: The Complete Guide.
Hyper-V #
The Microsoft Hyper-V hypervisor is provided free with Windows 10 and 11 Professional and Enterprise. (Windows Home users must use WSL2.)
To install Hyper-V:
-
Enable hardware virtualization support in your BIOS.
This will be active on most devices, but check by rebooting and accessing your PC’s BIOS panels – typically by hitting DEL, F2, or F10 as your system starts. Look for Virtualization Technology, VTx or similar options. Ensure they are enabled, save, and reboot.
WARNING! Be careful when changing BIOS settings – one wrong move could trash your PC.
-
Enable the Hyper-V option in the Turn Windows features on or off panel then reboot.
This can be accessed by hitting the Start button and typing the panel name or from Programs and Features in the classic Control Panel.
You can now install Docker Desktop.
Install Docker Desktop for Windows #
Docker Desktop for Windows 10 and 11 can be downloaded from Docker Hub. The installer includes the Docker server, CLI, Docker Compose, Docker Swarm, and Kubernetes.
Two editions are available: stable and edge with experimental features. The stable version is best for most developers.
Double-click Docker Desktop Installer.exe
to start the installation process. After completion and launch, the whale icon in the notification area of the task bar indicates Docker is running and ready to accept commands in the Windows Powershell/cmd
terminal (and Linux if using WSL2).
Docker Engine Settings #
Docker uses WSL2 as the default engine when available. You will be prompted to confirm this choice during installation and after WSL2 is installed.
Alternatively, WSL2 can be enabled by checking Use the WSL 2 based engine in the General tab of Settings accessed from the Docker task bar icon. Unchecking the option reverts to Hyper-V.
When using WSL2, at least one Linux distro must be enabled – the default is chosen. You can also permit Docker commands in other distros by accessing the WSL integration panel in the Resources section of the Docker Settings:
When using Hyper-V, Docker must be granted access to the Windows file system. Select the drives it is permitted to use by accessing the File Sharing panel in the Resources section of the Docker Settings:
(This option was named Shared Drives in previous editions of Docker Desktop.)
Test your Docker installation #
Check Docker has successfully installed by entering the following command in your terminal:
docker version
A response similar to the following is displayed:
Client: Docker Engine - Community
Version: 19.03.12
API version: 1.40
Go version: go1.13.10
Git commit: abcdef0
Built: Mon Jun 22 15:45:36 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.12
API version: 1.40 (minimum version 1.12)
...etc...
Ensure Docker Compose is working by entering:
docker-compose version
To receive something like:
docker-compose version 1.27.2, build 8d51620a
docker-py version: 4.3.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.1c 10 Sep 2019
Optionally, try entering:
docker run hello-world
to verify Docker can pull an image from Docker Hub and start containers as expected…
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows your installation appears to be working correctly.
Key points #
What you’ve learned in this chapter:
- How to install and configure Docker on your Linux, macOS, or Windows system.
- How to install Docker Compose.
- How to test the Docker installation.
The following chapters demonstrate how to use Docker during development…
…but to continue reading, you need to buy the book.
Do you want an easy-to-follow course which demonstrates how to use Docker and create practical web development environments on your Windows, macOS, or Linux PC?
Buy the «Docker for Web Developers» book & video course…
-
full course
$99 $50 £43 / €49
buy all
-
ebooks only
$30 $15 £13 / €15
buy books
-
videos only
$80 $40 £34 / €40
buy videos
plus your country’s sales tax where applicable
Docker Desktop for Windows is the Community Edition (CE) of Docker for Microsoft Windows. To download Docker Desktop for Windows, head to Docker Hub.
Link: https://hub.docker.com/editions/community/docker-ce-desktop-windows
The installation provides Docker Engine, Docker CLI client, Docker Compose, Docker Machine, and Kitematic. Containers and images created with Docker Desktop for Windows are shared between all user accounts on machines where it is installed. This is because all Windows accounts use the same VM to build and run containers.
Did you Know? Switch between Windows and Linux containers describes the Linux / Windows containers toggle in Docker Desktop for Windows and points you to the tutorial mentioned above.
Pre-requisite:
- Windows 10 Laptop 10.0.143393 Build 14391
- x64 based PC
- Verify if Switch to Linux container is well selected under Preference UI
System Requirements:
- Windows 10 64bit: Pro, Enterprise or Education (1607 Anniversary Update, Build 14393 or later).
- Virtualization is enabled in BIOS. Typically, virtualization is enabled by default. This is different from having Hyper-V enabled. For more detail see Virtualization must be enabled in Troubleshooting.
- CPU SLAT-capable feature.
- At least 4GB of RAM.
Checking Docker Version
Run docker version to check the basic details of your deployment. You should see “Windows” listed as the operating system for the Docker client and the Docker Engine:
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:31 2019
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: true
Kubernetes:
Version: v1.10.11
StackAPI: Unknown
PS C:\Users\Ajeet_Raina>
The OS/Arch field tells you the operating system and CPU architecture you’re using. Docker is cross-platform, so you can manage Windows Docker servers from a Linux client and vice-versa, using the same docker commands.
Running Your First NGINX application
PS C:\Users\Ajeet_Raina> docker run -d -p 80:80 nginx
567450d768e42e521bf3cec945d07bc3f796b6c5503d971881f5169e30a73215
Running Your First Nginx based Docker Container
PS C:\Users\Ajeet_Raina> docker run -d -p 81:80 ajeetraina/hellowhale
33e673c86f63990cdac2c155bc6bfe20a7b7809b82434908bc38517ae029d0e8
Try running WIndows Based Docker Container
PS C:\Users\Ajeet_Raina> docker container run -d -p 84:80 --name iis microsoft/iis
Unable to find image 'microsoft/iis:latest' locally
latest: Pulling from microsoft/iis
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: no matching manifest for unknown in the manifest list entries.
See 'C:\Program Files\Docker\Docker\Resources\bin\docker.exe run --help'.
PS C:\Users\Ajeet_Raina>
This was expected as we are currently switched to Linux containers
Creating Docker Swarm Cluster on Windows
PS C:\Users\Ajeet_Raina\docker101\play-with-docker\wordpress> docker swarm init
Swarm initialized: current node (29g3oqgz89f9g7gyicgq8h1o2) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1gz58w1cgci63er4dhl6rkhhg29umkkt373ic85hpb3ywvtvqg-4ersf0a9dz00ime4xy
168.65.3:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
PS C:\Users\Ajeet_Raina\docker101\play-with-docker\wordpress>
Verifying Single Node Cluster
PS C:\Users\Ajeet_Raina\docker101\play-with-docker\wordpress> docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE
VERSION
29g3oqgz89f9g7gyicgq8h1o2 * linuxkit-00155d1fffe2 Ready Active Leader 18.09.
2
Running WordPress Application on Docker Desktop for Windows
Let us first stop the last 2 containers which listen on port 80 and 81 and then follow the below command to bring up WordPress App
PS C:\Users\Ajeet_Raina\docker101\play-with-docker\wordpress\example1> docker stack deploy --orchestrator=swarm -c stack.yml myapp10
.yml myapp10
Ignoring unsupported options: restart
Creating network myapp10_default
Creating service myapp10_db
Creating service myapp10_wordpress
PS C:\Users\Ajeet_Raina\docker101\play-with-docker\wordpress\example1>
Verifying the Stack
PS C:\Users\Ajeet_Raina\docker101\play-with-docker\wordpress\example1> docker stack --orchestrator=swarm ls
NAME SERVICES ORCHESTRATOR
myapp10 2 Swarm
PS C:\Users\Ajeet_Raina\docker101\play-with-docker\wordpress\example1>
Running Docker Swarm Visualizer
PS C:\Users\Ajeet_Raina\docker101\play-with-docker\visualizer> docker-compose up -d
WARNING: Some services (visualizer) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configu
ration - use `docker stack deploy` to deploy to a swarm.
WARNING: The Docker Engine you're using is running in swarm mode.
Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the c
urrent node.
To deploy your application across the swarm, use `docker stack deploy`.
Creating network "visualizer_default" with the default driver
Pulling visualizer (dockersamples/visualizer:stable)...
stable: Pulling from dockersamples/visualizer
88286f41530e: Pull complete
6a722742375f: Pull complete
7e9d2f284de4: Pull complete
a8a42e9e643e: Pull complete
878a9d1427c8: Pull complete
b1867f55f80a: Pull complete
1a82a234b70b: Pull complete
93d560de8dd8: Pull complete
3eb2a9bba107: Pull complete
67cde5cd35b3: Pull complete
b4376f83977c: Pull complete
730e0303ceca: Pull complete
Creating visualizer_visualizer_1 ... done
PS C:\Users\Ajeet_Raina\docker101\play-with-docker\visualizer>