still broken in 1.12.1-beta24 . setting a remote host works, but i think it is important to use remote connect back, so this will work on different environments like toolbox-mac, docker mac, linux …
Try IP from here as xdebug.remote_host : cat /Users/<YOUR_USERNAME>/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host
This used to work for me using the Docker for Mac beta, but after updating to v1.12.1 stable, the mentioned file no longer exists…
Is there any way to get this IP without setting up a loopback IP? If not, there should be.
I used to use the loopback alias. It works great but if you don’t have any network connection (no wifi), the connection between xdebug and the host can’t be established.
Has someone an idea on how to resolve this ? and ensure that the connection will work even if you work offline ?
On a windows host, I got this to work by using the IPv4 address used by the vEthernet (DockerNAT) connection. Just check your network connections, view that specific connection’s details to get the ip address and plug that into your xdebug.remote_host. I also had to enable remote_autostart (for some reason, I could never get xdebug to trigger using GET/POST/cookies)
Thank you for suggestion about DockerNAT address on Windows 10 host. Also, for me following configuration was enough:
xdebug.remote_host=10.0.75.1
xdebug.idekey=PHPSTORM
xdebug.remote_enable=1
xdebug.remote_autostart=0
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 xdebug.remote_connect_back.
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_enable=on
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
Thanks for this excellent thread - I’ve been struggling with with the same XDebug problem with mac and PHPStorm and stumbled on to a slightly better way to setup your php.ini if you’re using Docker For Mac 17.06+:
At least this eliminates a static IP which is annoying if you’re on DHCP. I’m working on a new image that will hopefully be able to do a detection if it’s Docker For Mac or not and setup the php.ini this way if so, otherwise use remote_connect_back.