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!
Please sign in to leave a comment.
Sorry, missed this thread! Is the issue still actual?
SOLVED: while I was collecting debug information below, I found that for PHPStorm helper container Docker does not create correct network settings. I set manually in “Settings | Test Frameworks | MySetting | Docker Container | network mode” the actual name of network “datahost_default” (by default there was “bridge”) as in network setting from mariadb container and now all works fine.
It looks like the setting “network mode” is misleading in it's name and default value.
----
Original message:
Yes, the issue is still actual. I have faced it now.
Docker run command:
All works fine through browser or CLI.
Tests work fine if I run them through console:
Network Container Info of mariadb container
Container Info phpstorm_helpers_PS-233.14475.35