
For full functionality of the project on Docker in WSL, it is necessary to install WSL 2. As of the writing of this note, its use is only possible as part of participation in the Windows Insider Program (WSL 2 is available in builds 18932 and higher). It is also worth mentioning that a Windows 10 Pro version is required for installing and configuring Docker Desktop.
First Steps
After joining the Insider Program and installing updates, it is necessary to install the Linux distribution (Ubuntu 18.04 is used in this example) and Docker Desktop with WSL 2 Tech Preview:
In both cases, follow the installation and configuration instructions.
Installing the Ubuntu 18.04 distribution
Before launching Ubuntu 18.04, you need to enable Windows WSL and Windows Virtual Machine Platform by executing two commands in PowerShell:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux(will require a computer restart)Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
Next, you need to ensure that we are using WSL v2. For this, in the WSL terminal or PowerShell, execute the following commands in sequence:
wsl -l -v— check what version is currently installed. If it is 1, proceed further down the list.wsl --set-version ubuntu 18.04 2— to upgrade to version 2.wsl -s ubuntu 18.04— set Ubuntu 18.04 as the default distribution.
Now you can launch Ubuntu 18.04, go through the setup (specify username and password).
Installing Docker Desktop
During the installation process, follow the prompts. The computer will require a restart after the installation and at the first launch to enable Hyper-V (due to which Windows 10 Pro is required).
Vigtigt! If Docker Desktop reports a firewall blockage, go to the antivirus settings and make the following changes to the network rules (in this example, Kaspersky Total Security is used as the antivirus):
- Go to Settings -> Protection -> Firewall -> Configure packet rules -> Local Service (TCP) -> Change
- Remove port 445 from the list of local ports.
- Save
After launching Docker Desktop, select the WSL 2 Tech Preview option from its context menu.

In the opened window, click the Start button.

Now docker and docker-compose are available inside the WSL distribution.
Vigtigt! In the updated Docker Desktop, there is now a tab with WSL inside the settings window. Enable support for WSL there.

Vigtigt! Udover at aktivere WSL er det også nødvendigt at aktivere din WSL-distribution i fanen Resources->WSL Integration.

Kørsel
En overraskelse var de mange problemer, der opstod, når jeg forsøgte at starte containerne for projekterne, der lå i Windows-brugermappen.
Forskellige fejl relateret til kørsel af bash-scripts (som normalt startes under opbygningen af containerne for at installere de nødvendige biblioteker og distributioner) og andre ting, der almindeligvis er forbundet med udvikling på Linux, fik mig til at overveje at placere projekterne direkte i Ubuntu 18.04-brugermappen.
.
Fra løsningen på det tidligere problem følger det næste: hvordan man arbejder med projektfiler gennem en IDE installeret på Windows. Jeg har kun fundet én variant som "best practice" — arbejde via VSCode (selvom jeg er fan af PhpStorm).
Efter download og installation af VSCode er det vigtigt at installere udvidelsen .
Efter installation af den ovennævnte udvidelse er det nok at udføre kommandoen code . i projektmappen med VSCode åbnet.
I dette eksempel er nginx nødvendig for at få adgang til containerne via browseren. At installere det via sudo apt-get install nginx var ikke så ligetil. Først skulle WSL-distributionen opdateres ved at udføre sudo apt update && sudo apt dist-upgrade, og først derefter kunne installationen af nginx startes.
Vigtigt! Alle lokale domæner er ikke angivet i filen /etc/hosts for Linux-distributionen (den findes ikke engang), men i hosts-filen (som normalt ligger C:WindowsSystem32driversetchosts) på Windows 10.
Kilder
En mere detaljeret beskrivelse af hvert trin findes her:
Kilde: habr.com
