Phpstorm Wsl2 Docker



Docker

  1. Phpstorm Wsl2 Dockers
  2. Phpstorm Wsl2 Docker
  3. Phpstorm Wsl2 Docker Tutorial
  4. Intellij Docker Wsl 2

Phpstorm Wsl2 Dockers

Well something went horribly wrong with my laptop. After a few hours tons of little background tasks would start using 100% of the CPU. Death by a thousand cuts.

Start Docker Desktop from the Windows Start menu. From the Docker menu, select Settings General. Select the Use WSL 2 based engine check box. If you have installed Docker Desktop on a system that supports WSL 2, this option will be enabled by default. I’m running a Magento2 PHP app inside a set of docker containers that are orchestrated by docker-compose locally. I’m running Docker Desktop for Windows in WSL2 mode.

So I decided to take the plunge and install the recently released Windows v2004. I was excited because the version of WSL 2 that comes with that has a real linux kernel running in a cool, super integrated HyperV VM. Docker-Desktop had cleverly figured how to also run on that VM so it would theoretically not be such a resource hog and have faster file access.

Here is the setup:

PhpStorm IDE running in Windows proper

Project files (aka the code I work on) in Windows proper(for faster indexing and external change detection)

WSL2 running (obviously) in the HyperV VM

Kubernetes running in Docker-Desktop’s namespace in the HyperV VM

Everything was going swimmingly until I discovered PHP storm does not yet support running git under WSL. Well, bummer. I like having the ability to use git in WSL as well as directly in the IDE. So I guess I have to install and maintain 2 versions of git (and the AWS CLI since our code is in AWS CodeCommit and requires an AWS MFA git credential helper to access).

The next issue though was a *real* downer. General provider usb devices driver download for windows 10. This little gem which isn’t mentioned anywhere in the docker-desktop docs: “Unfortunately we don’t support hostpath volumes in wsl2.“

Kubernetes hostPath volumes are incredibly useful when doing development of applications destined to run in a kubernetes environment (the primary reason I want to use docker-desktop in the first place). They allow you to run containers in k8s that look to the local file system for config or (for interpreted languages) code changes. It’s hard to overstate how efficient it is to have your changes immediately take effect without the need to rebuild and redeploy your containers.

Phpstorm Wsl2 Docker

But now that is gone because I guess the docker-desktop peeps couldn’t figure out how to access arbitrary folders in WSL from their namespace in the HyperV VM.

BUT (as mentioned in the link above) there is a single magical directory in WSL that provides just such access.

“/mnt/wsl”

That’s its name in WSL anyway. In the HyperV VM where docker-desktop it is mounted at “/run/desktop/mnt/host/wsl”

So what I ended up doing was creating a “/mnt/wsl/host-path-bridge” directory and putting all the directories I wanted to share with k8s containers as hostPaths there.

Then in the actual k8s manifest when defining the hostPath, I used the path accessible by docker-desktop: “/run/desktop/mnt/host/wsl/host-path-bridge”.

Since one of the things I wanted to share was PHP code that is actually living in the Windows proper file system (because PHPStorm) I had to make a copy of the code in a “/mnt/wsl/host-path-bridge/git-wa/code2” directory. I then added a windows .bat script to the PHPStorm File Watcher tool that runs anytime I change a file and copies that file to the proper place in the “/mnt/wsl/host-path-bridge/git-wa/code2” directory.

Here is that script:

@REM This copies a provided file / directory from the standard core2 work area
@REM on Windows to the special directory in WSL2 that allows K8s pods to mount it
@REM as a shared volume.
@REM To be used in conjunction with PHPStorm's File Watchers Tool
@echo off
setlocal enabledelayedexpansion
set srcRoot=C:Usersusernamegit-wacore2
set dstRoot=Z:mntwslhost-path-bridgegit-wacore2
set src=%srcRoot%%1%
set dst=%dstRoot%%1%
xcopy /s/y/h %src% %dst%

Here is the PHPStorm File Watcher setup:

Phpstorm Wsl2 Docker Tutorial

What I ended up with is a Rube Goldberg machine, but it allows me to use my IDE like I want with fast indexing and built-in git functionality in Windows proper while still running a facsimile of our system in a local kubernetes cluster using docker-desktop running in WSL.

A ProxyCap aside

Intellij Docker Wsl 2

Had trouble using proxy cap (the way we access interal services over an SSH tunnel). This was the problem: https://github.com/microsoft/WSL/issues/4177. I was able to remedy using the NoLsp.exe tool mentioned in that issue.