Debugging Php inside a Docker container

01 Oct 2016

I recently moved our Development environment in work to Docker and found that debugging wasn’t as straigth forward as before

I had spent half a day trying different things including this solution I came across on

I had my docker php.ini set up for xdebug:

xdebug.var_display_max_children = 999
xdebug.var_display_max_data = 999
xdebug.var_display_max_depth = 100

I had the xdebug chrome extension installed

In my laptop host file I have the following localhost so I can access my web app (and other docker web apps) through which worked fine to run the app

In Phpstorm (version 2016.1.2) In preferences -> Languages & Frameworks -> PHP -> Servers I have :

host =, port=80 , Debugger = Xdebug
Use path mappings is checked and I have

  • File/Directory set to /Users/<myname>/projectx/server
  • Absolute path on the server is set to /projectx/server

I have tried setting the xdebug.remote_host to my macs ip obtained from ifconfig as well as trying the ip in


But I could not hit a breakpoint , I even tried xdebug_break() to be sure it wasn’t an issue with Phpstorm.

###Workaround and Final Solution I figured out a workaround by opening an ssh tunnel to the docker container (note the -p 12 is because I had ssh exposed through port 12)

ssh -R 9000:localhost:9000 -p:12

But I wasn’t happy with this, it meant I need ssh set up in my container.I eventually figured out that my xdebug settings in docker should be

xdebug.remote_enable = 1

where was docker host ip found in


I Also had to set the idekey correctly in the chrome extension, in my case PHPSTORM. With this I no longer required the ssh tunnel