
For full-fledged work with a project on Docker in WSL, WSL 2 needs to be installed. At the time of writing this note, its use is only possible within the Windows Insider Program (WSL 2 is available in builds 18932 and higher). It is also worth mentioning that Windows 10 Pro is required for the installation and configuration of Docker Desktop.
FĂžrste skritt
After joining the Windows Insider Program and installing the updates, it is necessary to install a Linux distribution (in this example, Ubuntu 18.04 is used) and Docker Desktop with WSL 2 Tech Preview:
In both cases, follow all the installation and configuration instructions.
Installing the Ubuntu 18.04 distribution
Before starting 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 make sure that we are going to use WSL v2. To do this, sequentially execute the commands in the WSL terminal or PowerShell:
wsl -l -vâ check which version is currently installed. If it is 1, then proceed to the next items on the list.wsl --set-version ubuntu 18.04 2â to update to version 2.wsl -s ubuntu 18.04â set Ubuntu 18.04 as the default distribution.
Now you can start Ubuntu 18.04 and complete the setup (specify the username and password).
Installing Docker Desktop
During the installation process, follow the prompts. The computer will require a restart after the installation and on the first run to enable Hyper-V (which is required for Windows 10 Pro).
Viktig! If Docker Desktop reports a firewall block, go to the antivirus settings and make the following changes to the network firewall rules (in this example, Kaspersky Total Security is used as the antivirus):
- Navigate to Settings -> Protection -> Firewall -> Configure Network Rules -> Local Service (TCP) -> Edit
- From the list of local ports, remove port 445.
- Save
After starting 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 within the WSL distribution.
Viktig! In the updated Docker Desktop, there is now a tab with WSL inside the settings window. There, WSL support can be enabled.

Viktig! I tillegg til Ä aktivere WSL-flagget mÄ du ogsÄ aktivere WSL-distribusjonen din i fanen Resources->WSL Integration.

Start
Mange problemer oppsto overraskende nok da jeg prĂžvde Ă„ heve containerne til prosjekter som ligger i brukerens Windows-katalog.
Ulike feil relatert til kjĂžring av bash-skript (som vanligvis starter ved bygging av containere for Ă„ installere nĂždvendige biblioteker og distribusjoner) og andre vanlige utviklingsoppgaver for Linux fikk meg til Ă„ vurdere Ă„ plassere prosjektene direkte i brukerens katalog for Ubuntu 18.04.
.
Fra lĂžsningen pĂ„ det forrige problemet fĂžlger det neste: hvordan jobbe med prosjektfiler gjennom en IDE installert pĂ„ Windows. Som 'beste praksis' fant jeg kun Ă©n lĂžsning â Ă„ jobbe via VSCode (selv om jeg er fan av PhpStorm).
Etter nedlasting og installasjon av VSCode, installer nĂždvendigvis utvidelsen .
Etter installasjonen av den nevnte utvidelsen er det bare Ä utfÞre kommandoen code . i prosjektkatalogen nÄr VSCode er Äpnet.
I dette eksempelet er nginx nÞdvendig for Ä fÄ tilgang til containerne gjennom nettleseren. Installer det ved Ä bruke sudo apt-get install nginx var ikke sÄ enkelt. FÞrst mÄtte jeg oppdatere WSL-distribusjonen ved Ä kjÞre sudo apt update && sudo apt dist-upgrade, og fÞrst etter det kunne jeg starte installasjonen av nginx.
Viktig! Alle lokale domener skrives ikke i filen /etc/hosts til Linux-distribusjonen (den finnes ikke engang), men i hosts-filen (vanligvis plassert i C:WindowsSystem32driversetchosts) pÄ Windows 10.
Kilder
En mer detaljert beskrivelse av hvert steg kan finnes her:
Kilde: habr.com
