Docker Community Forums

Share and learn in the Docker community.

IP address for xdebug


(Pgosselin82) #21

That’s how I do it:

  • sudo ifconfig lo0 alias 10.254.254.254 (create an alias for your mac loopback interface)
  • xdebug.remote_host=10.254.254.254 in your xdebug.ini
  • configure your ide as usual.

I’ve been using this through several beta versions, never had a problem. Beware of port 9000 conflicts.


(Ralphschindler) #22

A startup script to standardize on using 10.254.254.254:


(Claudiu Creanga) #23

Are you using docker for mac or toolbox? Those settings work for me if I use toolbox, but don’t work on docker for mac.


(Achretien) #24

You can use 172.0.0.1 as xdebug.remote_host in the xdebug.ini file


(Nonsenz) #25

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 …


(Ttorgeson) #26

I tried doing this… but then what IP/interface do you listen on inside the IDE? (In this case, PhpStorm)


(Toozick) #27

Man I have looked through so many Docker forum and StackOverflow posts but can’t seem to get it to work. Does somebody mind looking at our setup and finding the problem? https://gist.github.com/Toosick/4639f4e33ad52c692876a89df89e2b40


(Adam Biggs) #28

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.


(Mickaelperrin) #29

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 ?

Thanks,


(Vrann) #30

Instead of creating loopback workaround, you can also use ssh tunnel with this configuration:
xdebug.remote_connect_back = 0
xdebug.remote_host=127.0.0.1
Posted full solution here http://stackoverflow.com/questions/40666083/xdebug-with-ssh-tunnel-on-docker-for-mac


(James Cowie) #31

After much pain I got this working with the following:
Dockerfile

RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y \
    && apt-get install -y git curl \
    && pecl install xdebug \
    && rm -rf /tmp/pear \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)\n"
       >> /usr/local/etc/php/conf.d/xdebug.ini

PHP.ini

xdebug.remote_host=10.254.254.254
xdebug.remote_autostart=1
xdebug.idekey = PHPSTORM
xdebug.default_enable = 0
xdebug.remote_enable = 1
xdebug.remote_connect_back = 0
xdebug.profiler_enable = 1

sudo ifconfig en0 alias 10.254.254.254 255.255.255.0

I wrote up and recorded my workflow here: Debugging PHP apps

Hope this helps someone.


(Georald Camposano) #32

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)


(Bmagrys) #33

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


(Jorge) #34

I wrote that for our company php image, it can be useful for someone: https://github.com/jorge07/alpine-php/blob/master/doc/IDE.md


(Enderandpeter) #36

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

(Kducharm) #37

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+:

xdebug.remote_enable=1
xdebug.remote_host=docker.for.mac.localhost
xdebug.remote_connect_back=0

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.


(Rasmartin) #38

Thank you! Work perfect :slight_smile:


(Llt104) #39

This really helped me! Specifically the xdebug.remote_host=docker.for.mac.localhost part. Any ideas what this means?


(Cobers) #40

nice, it’s works.