Integrating Docker with Xdebug and Sublime Text on PHP environment

I’m setting up a Docker development environment for my team. In this environment we want to integrate Xdebug with Docker to allow for debugging. It seems the easiest way to do this is to connect Sublime Text to the Docker instance and then install Xdebug ontop on Sublime Text. I found the following guide for integrating Sublime Text with Docker ( and this guide for integrating Xdebug with Sublime Text ( What I am wondering is if anyone has any experience setting up similar environments? Is there an easier way to do this? Does this seem like the correct way to debug PHP code inside Docker?

  • How to increase the swap space available in the boot2docker virtual machine?
  • Linode/lamp + docker-compose
  • Port published via Docker — can't connect
  • Unable to start Docker Container with ONOS
  • Not able to access to Docker container through bound public ip
  • Login to AWS's ECR fails
  • Docker Private Registry - push to 'insecure-registry' still complains about 'unknown authority'
  • How to skip a gradle task under some cases, which introduced by the bmuschko/gradle-docker-plugin?
  • Restart docker container from another container
  • RabbitMQ on Docker: Pika hangs on connection when given port, connection refused without port
  • Docker Permission Denied run docker as nginx
  • Error accessing host port from docker container on ubuntu
  • One Solution collect form web for “Integrating Docker with Xdebug and Sublime Text on PHP environment”

    This solution may also work for Sublime Text – For Visual Studio Code, I have just recently got this working. I found these remote_host and other Xdebug settings work for me on both Windows 10 Pro and OS X using the latest versions of Docker Community Edition.

    In the Xdebug extension configuration, I set these along with the Xdebug extension installation in the Dockerfile of the image package from docker hub that contains php. There is a link to a post at the bottom of this answer on how this was done in the Dockerfile and how the image was built and then added to the docker-compose file.

    1. The xdebug.remote_connect_back setting needs to be off: xdebug.remote_connect_back=0
    2. Autostart xdebug.remote_autostart=1 it just works.
    3. xdebug.remote_host= needs to be changed depending on Windows or OS X as follows:

    Windows 10 Professional running Docker Version 17.03.0-ce-win1, open a command prompt and enter ipconfig. The address is listed under DockerNAT. For example:

    Ethernet adapter vEthernet (DockerNAT):
        IPv4 Address. . . . . . . . . . . :

    OS X El Capitan running Docker Version 17.03.0-ce-mac2, create an alias of IP to your existing subnet mask.

    sudo ifconfig en0 alias

    Then use the IP for the xdebug.remote_host setting for your host as follows based on the examples above:

    1. Windows
    2. OS X:

    Note, if you run into a conflict in OS X, you can remove the alias like so.

    sudo ifconfig en0 -alias

    I use Visual Studio Code with the vscode-php-debug PHP Debug Adapter to Listen for Xdebug and step through my code. Note the following needs to be included in the project launch.json file in order for VS Code to map the remote server files to the local machine. This is from my project and its typical volume locations, your serverSourceRoot looks to be the same.

    "serverSourceRoot": "/var/www/html",
    "localSourceRoot": "${workspaceRoot}"

    The entire setup for docker-compose, nginx-proxy including how to build the image with Xdebug and more at Docker WordPress Dev Environment – Remote Debugging with Xdebug and VS Code

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.