lando/hyperdrive

Access Linux Docker from Windows

quentint opened this issue · 2 comments

I recently moved one of my "Windows Lando" projects to the "Windows WSL Hyperdrive" setup and need to connect to this setup's Docker to use my PHPStorm PHPUnit recipe.

I'm stuck trying to setup Docker in PHPStorm.

Is WSL's Docker (installed by Hyperdrive) accessible from Windows?
Can you help me with that?

Thanks!

After digging a bit I realized I may just need to be able to access the *_appserver_1 container (should be enough to use the PHP CLI interpreter), and not necessarily Docker itself.

I tried with https://github.com/jeroenpeeters/docker-ssh but I currently face these issues when SSH'ing:

  • PTY allocation request failed on channel 0
  • exec request failed on channel 0

Still investigating...

Recently found a way to work this out 🎉
Here's a quick guide to do so.

Running PHPUnit tests in IntelliJ IDEA or PhpStorm

For this setup to work you have to:

  1. Have your IDE in Windows
  2. Have your project in Lando, in WSL
  3. Have Windows Docker Desktop with:
    1. General > Use the WSL 2 based engine
    2. Resources > WSL Integration > Enable integration with my default WSL distro (and maybe check other distros, then refresh)

Here are the IDE settings you need:

  • Go to Build, Execution, Deployment
    • Docker > + > Docker for Windows
  • Go to PHP
    • CLI Interpreter
      • ... > + > From Docker, Vagrant...
        • Docker Compose
        • Configuration files > All YAML files in //wsl$/Ubuntu/home/[user]]/.lando/compose/[project]/
        • Service > appserver
        • OK
        • Lifecycle > Connect to an existing container
    • Path mappings
      • [Folder icon] > +
        • Local Path = [WSL Project home] > Remote Path = /app
    • In PHP, go to Test frameworks > + > PHPUnit by Remote Interpreter
      • appserver
        • PHPUnit library > Path to phpunit.phar > bin/phpunit
        • [✓] Default configuration file: /app/phpunit.xml.dist

Warning: First test runs will fail with "Could not open input file: bin/phpunit", but subsequent should work just fine.