Containers cannot reach one another when running phpunit tests via WSL interpreter when Docker is installed in WSL (not Windows)

I've spent quite a bit of time trying to find an example of somebody else trying to make this work, and have come up empty. In every other example I can find, the user has installed Docker for Windows.

By contrast, I have installed the Docker binaries in WSL only, specifically because overall performance it is significantly faster when my project source resides in the WSL volume and Docker is also running in WSL.

This setup works perfectly fine with respect to running the application in a browser.

However, when I run phpunit, the various Docker containers cannot reach each other over the Docker network. I get errors like this:

php_network_getaddresses: getaddrinfo for redis failed: Name or service not known

This sort-of makes sense, because it seems like PhpStorm is actually invoking phpunit from within the context of the WSL host OS, e.g., Ubuntu 20.04, as can be seen in the actual command that it executes:

[\\wsl$\Ubuntu-20.04]:/usr/bin/php --distribution Ubuntu-20.04 --exec /bin/sh -c "export TERM=xterm && export IDE_PHPUNIT_CUSTOM_LOADER=/home/ben/project/vendor/autoload.php && cd /home/ben/project/tests && /usr/bin/php /home/ben/project/vendor/phpunit/phpunit/phpunit --configuration /home/ben/project/tests/phpunit.xml --teamcity"

In other words, it doesn't seem like PhpStorm is actually logging into the application container to execute `phpunit`.

After digging deeper, I thought that I had perhaps chosen the wrong interpreter type when I chose "WSL". So, instead, I chose "Docker", and set the Server to the Docker app container in which the php binary resides. But, the result is more or less the same (albeit with a slightly different command invoked):

[docker://project-php:latest/]:php /opt/project/vendor/phpunit/phpunit/phpunit --configuration /opt/project/tests/phpunit.xml --teamcity

This seems a bit closer to what I expect. PhpStorm appears to create a "helper" Docker container that runs in the appropriate context, but for whatever reason, it can't reach my app's other service containers either.

Am I overlooking something? Or am I trying to do something that isn't possible?

Thanks in advance for any insight!


1 comment

Sorry, missed this thread! Is the issue still actual?


Please sign in to leave a comment.