Configuring PhpStorm with Docker Desktop + Windows 11 + WSL2

I'm not understanding why it works this way but when I installed Docker Desktop for Windows 11, it forced me to use WSL2.  Docker desktop created its own WSL2 installation titled “docker-desktop” and “docker-desktop-data”:

wsl -l -v
 NAME                   STATE           VERSION
* docker-desktop         Running         2
 Ubuntu-22.04           Running         2
 docker-desktop-data    Running         2

When I go to Open a new project in PHP storm (and even VS Code) they can only see the “Ubuntu-22.04” under the WSL option.  Why?

How are you guys setting up Docker Desktop to work with PHPStorm?  Is the only way to do it to install docker on the Ubuntu-22.04 WSL2 installation?  Then run docker from there?  I would much prefer to use the docker desktop application vs the command line… As it just easier than remembering all of the commands.

I was able to set it up and use “bind mounts” to be able to pass code to the docker containers but performance was horrible (2-5+ second page loads).  I switched to using “volumes” within docker which fixed performance problems (back to instant page loads) but then the problem is I cannot access my code because it lives within the “docker-desktop-data” wsl2 installation.

0
1 comment

I'm surprised no one has responded to this.  There is no access to the docker-desktop-data machine; it's for Docker's exclusive use. That's why, when coding with Docker, it's best to do one of 2:
- Have your project on Windows' filesystem where it is then mounted into the docker container

or

- Have your project in Ubuntu, where the code folder is mounted into the docker container. 

 

Docker with WSL2 has better performance than the original WSL, but it doesn't involve PHPStorm directly.  

The bottom line is your code must be in a place where you can edit it, the docker-desktop-data container isn't it. 

 

Now, where PHPStorm and Docker are concerned is more for defining the PHP CLI interpreter. You can choose a local Windows interpreter, a Docker container, or WSL or you can either connect to a running container or run a Docker stack and identify which of the services has the interpreter. 

You can see more info on how to accomplish this here: PHP development environment | PhpStorm Documentation (jetbrains.com) 

0

Please sign in to leave a comment.