IDE debugging with Docker, nginx, PHP7-FPM and Xdebug IDE debugging with Docker, nginx, PHP7-FPM and Xdebug nginx nginx

IDE debugging with Docker, nginx, PHP7-FPM and Xdebug


But at Start listening for PHP Debug connection I get Port 9009 is busy

There is no need to expose Xdebug port in your Docker container, no need at all.

If you expose it .. Docker will be the one that listens on that port and forwards any connections into container. But it's IDE/VSCode/PhpStorm that must be listening it... because it's Xdebug that connects to IDE and NOT other way around.

Fix that first.

xdebug.remote_connect_back = 1

I recommend turning this off and specify actual host in xdebug.remote_host (docker.for.mac.localhost).

The IP detected by Xdebug with remote_connect_back option (depends on settings I guess, and the way how Docker works) very likely will not be the IP of the host machine. But that's what you need -- that's where your IDE (PhpStorm) / editor (VSCode) runs and Xdebug must be connecting to.


If you are on "Docker for Mac", then in you xdebug config file you can also use this:

xdebug.remote_host = host.docker.internal

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST
The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker for Mac.

The gateway is also reachable as gateway.docker.internal.