Alright, I'd like to add my two cents to this excellent thread.
So, normally, you could set
xdebug.remote_connect_back=on in order for Xdebug to connect to any client that makes a request to the server regardless of hostname/IP. When this is on, the
xdebug.remote_host setting is ignored.
For whatever reason, Docker for Mac prevents Xdebug from allowing such unrestricted connections. One reason could be because when you enable
xdebug.remote_connect it tries to connect to 127.0.0.1:9000, which is the IP of the request according to the container, probably due to how Docker for Mac integrates the networking of the host and container. As a result, it thinks that the request is coming from the container rather than the host. I'm not totally sure if this is what's happening, but it's my best guess.
I, like pretty much everyone else here, could not get Xdebug to work with such a Docker for Mac container until I disabled
It would appear that you can set
xdebug.remote_host to any hostname/IP that your host computer is identified by, not the IP that the container uses to identify your host, which typically starts with 172. You can set an alias IP on your host if you want, but it would appear that you can likewise use an IP already assigned to the host on the local network. In fact, Docker has a brief Xdebug tutorial where they do this. I was confused by their instructions to use the host's private IP because in other containers, like Vagrant and Docker via VirtualBox, you do have to set
xdebug.remote_host to the IP that the container identifies the host with, which is typically the the gateway IP of the container, or the one seen in the access logs.
And so, my working Xdebug config on a Docker for Mac container is simply the following:
xdebug.remote_host=10.0.0.5 # My host's IP on en1
xdebug.remote_port=9001 # 9000 is already in use on my host and therefore unavailable for the container