Udvikling med Docker pÄ Windows Subsystem for Linux (WSL)

Udvikling med Docker pÄ Windows Subsystem for Linux (WSL)

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:

  1. Docker Desktop WSL 2 Tech Preview
  2. Ubuntu 18.04 from Windows Store

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:

  1. Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux (will require a computer restart)
  2. 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.

Udvikling med Docker pÄ Windows Subsystem for Linux (WSL)

In the opened window, click the Start button.

Udvikling med Docker pÄ Windows Subsystem for Linux (WSL)

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.

Udvikling med Docker pÄ Windows Subsystem for Linux (WSL)

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

Udvikling med Docker pÄ Windows Subsystem for Linux (WSL)

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 Remote Development extension pack.

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

KĂžb pĂ„lidelig webhosting med DDoS-beskyttelse, VPS VDS-servere đŸ”„ KĂžb pĂ„lidelig webhosting med DDoS-beskyttelse, VPS VDS-servere | ProHoster