Xdebug inside Colima docker container doesn't connect to PhpStorm debugger on Mac

1.8k Views Asked by At

I am trying to use Colima to run an apache-php docker container. My uni provides docker images derived from upstream ones configured for our course using docker-compose.

The container works as it should but I can't get its Xdebug to connect to my PhpStorm.

This is what it says in the Xdebug log:

Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).

This tells me absolutely nothing.

The setup is admittedly quite complex (x86 Apache ran via QEMU in Docker in Linux VM in macOS on ARM CPU) but I can do nc host.docker.internal 9003 from any docker container, so I have no idea why Xdebug isn't able to reach my host. (Only works when the IDE is running and on no other ports, so it's definitely connecting to PhpStorm.)

Any idea what could be going on here?

3

There are 3 best solutions below

0
On

The problem is the uni's docker-compose.yml which configured the container with:

    extra_hosts:
      - "host.docker.internal:host-gateway"

and apparently that can break host.docker.internal in some situations: https://github.com/docker/for-linux/issues/264#issuecomment-759737542

The solution is to remove those two lines.

2
On

On Colina, the IP address is hard coded to "192.168.5.2", so setting xdebug.client_host=192.168.5.2 should do the trick. There is now also an alias for it, called host.lima.internal. As per this documentation page.

0
On

Set:

xdebug.client_host=host.lima.internal instead xdebug.client_host=host.docker.internal

AND

xdebug.discover_client_host=0 instead xdebug.discover_client_host=1

in your php.ini config