Docker Community Forums

Share and learn in the Docker community.

[solved] How to setup xdebug and phpstorm

(Krodelabestiole) #1


I’m a bit confused using xdebug, docker for windows, and phpstorm…

i have xdebug configured in a container with PHP.
Here is what appears in my php.ini from within this container :

xdebug.remote_host={{some IP address}}

from this container i can’t access directly my Windows host IP, but i can access two IPs :
the docker host IP which is
and the docker IP i have from Windows (resolving docker) which is
why is there so many IPs ? what are there referring to exactly ?
i even can ping which might be some virtual bridge of some kind ?

xdebug communicates on port 9000. i have bind port 9000 to 9000 for this container :

        - "80:80"
        - "9000:9000"

from my understanding this binds port 9000 from this container to port 9000 on (docker from windows) ?
then what IP should i use for xdebug.remote_host ?
by default PHPStorm waits for some connection on port 9000, on local machine (Windows).
should I set what it calls a DBGp Proxy ? Pointing to docker ? On port 9000 ?

for now i have tried xdebug.remote_host with , or localhost and could not get it to work yet.

Xdebug doen't connect: Virtualhosts with Apache2 and PHP-FPM
(Krodelabestiole) #2

i’ve understood that xdebug.remote_connect_back bypass xdebug.remote_host setting, and set as a remote the http client machine. i guess then it should work in any case.
still, no luck either with or without DBGp Proxy set on host ‘docker’ and port 9000…

previously i had xdebug working with docker machine so i guess other settings are correct, but docker’s port 9000 was also bound to the Windows’ port 9000 using virtual box, then i guess it was considered as a local xdebug server by PHPStorm.

(Krodelabestiole) #4

i think i have a port issue :

my Windows IP as seen by docker seems to be (PHP shows for $_SERVER[‘REMOTE_ADDR’])
PHPStorm is listening to xdebug on port 9000.
therefore, when I telnet 9000 from windows it connects successfully when PHPStorm is listening and returns this error when it is not listening : “Could not open connection to the host on port 9000 : connect failed” . This makes perfect sense.
My web container is defined like this in docker-compose.yml :

    build: php5
        - "80:80"
        - "9000:9000"

And PHP shows for $_SERVER[‘REMOTE_ADDR’] . From this web container I can ping and telnet successfully on port 80 but on port 9000 it returns an error whether PHPStorm is listening or not :

root@fd60276df273:/var/www/html# telnet 9000
telnet: Unable to connect to remote host: Connection timed out

Windows firewall is off. Do you know what could cause this issue ?

(Krodelabestiole) #5


i think i’ve managed to strip my question down to the docker-for-windows core with this last post, so i would greatly appreciate to get an answer from you docker’s gurus.


(Michael Friis) #6

I don’t know anything about xdebug but I gather that you’re trying to connect from a container that’s running in Docker for Windows to an app that’s running and listening on a TCP port directly on the Windows 10 host?

That’s not really a supported scenario.

Having said that, there’s no reason it should not work. is probably the IP of your Windows host on the DockerNAT network (it is for me).

If I run a webserver on the Windows 10 host and make sure that it listens for external connections (listening on locahost will probably not cut it) and completely disable Windows Firewall, I can curl the webserver from a linux container running in Docker for Windows:

Hello from ASP.NET Core!

Note that this is not supported and that the networking setup may vary between machines and may change in the future.

(Krodelabestiole) #7

Thanks a lot for your answer :slight_smile:

I gather that you’re trying to connect from a container that’s running in Docker for Windows to an app that’s running and listening on a TCP port directly on the Windows 10 host?

That’s it.

That’s not really a supported scenario.

Really ? Why not ?

Anyway, I’ve just tried to telnet Windows from another computer on my local network, and telnet 9000 (which is my Windows IP) connects successfully. So I guess the problem I have is somehow inherent to docker or DockerNAT. Once again, i guess my firewall is completely disabled (at least it’s shown as turned off).
Should I change any setting on this DockerNAT virtual network interface ? I can’t see any way to open any port…

I’ve also tried to change xdebug port to some random other number and it doesn’t change anything…

(Krodelabestiole) #8

should i open a bug report or something ?

i think a docker container should really be able to connect to a listening service on windows.
xdebug is a major tool for web developers, who i guess are a big part of docker users. and i guess there are a bunch of other uses where this would be requested.

(Michael Friis) #9

You can join the fray here:


(Krodelabestiole) #10

thanks Michael !

though this threads are about using a host name to access host from a container. in this case i don’t want to resolve any IP, i guess i know my host IP and i would not even need it with xdebug.remote_connect_back.
all of these people don’t seem to have any issue to access a service on the host machine, and i had no issue either when i was using docker-machine - i just had to open a port on virtualbox.

i haven’t understood this solution :
i use docker-compose and “docker run --net” option doesn’t seem to exist anyway…

i’ve updated to the latest build, 1.12.0-rc2-beta16 and still no luck.
i’ve also tried to use the option “Expose container ports on localhost” but port 9000 then appears busy if it is bound for the container, and is still not accessible from the container anyway.

(Krodelabestiole) #11

ok i finally found this doc about networking :

and used option
network_mode: “host” in docker-compose

i can telnet 9000 ! i don’t know where this ip comes from (i found it with ifconfig) but it works when xdebug is listening, and not otherwise !

i will post more info soon.

(Krodelabestiole) #12

so here is how i got it to work

docker-compose.yml :

version: '2'

        build: php5
            - "80:80"
        #    - db:db
        network_mode: "host"
        image: mysql
            - "3306:3306"
            - MYSQL_ROOT_PASSWORD=root

php.ini :


i selected “Expose container ports on localhost” as well in docker settings.
i can’t use links any more, because of the specified network_mode. so i’ve opened port 3306 and i have to choose as mysql host. i will probably find some workaround about this, but finally it works ! im glad ! thanks Michael for having pointed this --net option.

(Visual4) #13

xdebug needs to connect back to your windows machine (PHPSTORM) on port 9000, so if networking in the container is working (should work if you have http and mysql up and running), you need to find out the windows IP on the docker-windows internal net and use this as xdebug.remote_host.

Or you use xdebug.remote_connect_back without specifying an IP at all - which works fine for me in conjunction with PHPStorm’s “Start Listening for PHP Debug connections”


(Krodelabestiole) #14

are you sure you are using docker for windows beta ?
because i’ve been trying to make it work for weeks without success : i could not access port 9000 on windows from the container, even through i had all networking ok, apt-get and all. it was not working with any windows IP i could get, neither with xdebug.remote_connect_back…
until i tried network_mode: “host” for the container, and still, xdebug.remote_connect_back doesnt work i have to use xdebug.remote_host=

(Visual4) #15

yes I am :-). Installed yesterday and imported data from my virtualbox instance.

1.12.0-rc2-beta16 with alpine linux on Hyper-V

this is part of my Dockerfile:
RUN echo “date.timezone= Europe/Paris” >> /etc/php5/fpm/php.ini
RUN touch /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “zend_extension =” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “xdebug.remote_enable = 1” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “xdebug.remote_connect_back = 1” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “xdebug.max_nesting_level = 1000” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “xdebug.profiler_enable_trigger = 1” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “xdebug.profiler_output_dir = “/var/log”” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “memory_limit = 512M” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “upload_max_filesize = 512M” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “post_max_size = 512M” >> /etc/php5/fpm/conf.d/40-custom.ini


(Larryeitel) #16

I know the pain!!!

Recently got a scaled-down version of Laradock working WITH full debugging!!! Checkout phpdock. The README outlines specific settings.

I decided to repo my docker-compose for two reasons. To share what it took for ME to get PHPStorm to play nice with Docker and to invite and refinements. It is called phpdock because at this point, I need to accommodate a variable number of php projects not necessarily Laravel all connecting to common services.

(Toozick) #17

I am having some problems and you seem to be able to get the remote_connect_back option to work over the remote_host one. Can you help?

(Visual4) #18

You don’t need 9000:9000 in docker, as it’s the container that will try to access your host - phpstorm acts as the server. Here your firewall might of course drop in, as some external process (the docker container) tries to contact your machine on port 9000.
You only need the following to get XDebug running:

RUN echo “zend_extension =” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “xdebug.remote_enable = 1” >> /etc/php5/fpm/conf.d/40-custom.ini
RUN echo “xdebug.remote_connect_back = 1” >> /etc/php5/fpm/conf.d/40-custom.ini

an of course you need to start XDebug by adding the XDebug Session Cookie manually, or with the Xdebug Helper Chrome extension.


(Toozick) #19

I have fixed my problem since but it’s not ideal like people have said. I am setting remote connect back to 0 and remote host to my host local ip. If I do the same and instead use the gateway IP that the containers have it doesn’t work. That would be ideal as that is what the containers get when you use remote connect back. You think a firewall might be stopping the connection on IP

(Otravers) #20

you need to find out the windows IP on the docker-windows internal net

Can you please explain how to do that?

(Visual4) #21

if you look at your logfile (Webserver log) you will see the IP, your requests come from. This should be the right one.