Using scratch files in WSL2 + Docker setup

I use Windows 10 Pro + Docker Desktop + WSL2 + Ubuntu. My code is stored in the Linux filesystem. The PHP interpreter runs inside a container and accesses those same files thanks to Docker magic. I run PhpStorm on Windows and access files through the \\wsl$ share. To sum one, one same file has three different paths depending on context:

  • From Windows: \\wsl$\Ubuntu-20.04\home\alvaro\project\foo.php
  • From Ubuntu: /home/alvaro/project/foo.php
  • From container: /var/www/html/foo.php

I'm very used to creating scratch files in PhpStorm to quickly test stuff. I currently need it mostly for two languages: PHP and Bash. I'm not sure of current support for all the involved technologies and I'm very new to Docker.

I can successfully set up a PHP interpreter in PhpStorm that points to the container, but it obviously can't access the scratch files directory, let alone with the Windows path. What are my options?

(I've installed an additional PHP interpreter on Windows, which would probably allow me to run PHP scratch files if there isn't a better solution, but I'm unsure about Bash, which I'd prefer to run in Ubuntu.)

0
3 comments

There's no support for running scratch files with remote interpreters: https://youtrack.jetbrains.com/issue/WI-27212
What kind of a Docker interpreter are you using, a Docker one or a Docker Compose one?

1

What kind of a Docker interpreter are you using, a Docker one or a Docker Compose one?

I guess the latter (I need docker-compose to build the image).

If remote PHP interpreters aren't supported I'm fine with a local interpreter. However, I'm unsure of the equivalent (if any) for Bash scripts. I don't need or want Docker for that but WSL2 shell is a must for me. In fact it's a problem for project scripts too—it calls the correct shell but uses Windows paths.

$ //wsl$/Ubuntu-20.04/home/alvaro/phpstorm-wsl/example.sh
-bash: //wsl$/Ubuntu-20.04/home/alvaro/phpstorm-wsl/example.sh: No such file or directory

0

I guess the latter (I need docker-compose to build the image).

I wanted to offer you a dirty hack of adding /mnt/c/Users/username/AppData/Roaming/JetBrains/PhpStorm2020.3/scratches as a PHP Include and as a volume mapping in docker-compose.yml, but apparently, you can't map such paths in WSL 2 Docker engine.

So yep, I am afraid there are no workarounds.

However, I'm unsure of the equivalent (if any) for Bash scripts. I don't need or want Docker for that but WSL2 shell is a must for me. In fact it's a problem for project scripts too—it calls the correct shell but uses Windows paths.

It's a known issue that has to be fixed by the IDEA team: https://youtrack.jetbrains.com/issue/IDEA-264320

3

Please sign in to leave a comment.