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 manage inter-dependant docker containers when moving between or cloning environments
  • docker mounted host directory file permissions
  • How to install a specific version of Java 8 using Dockerfile
  • How can I build a coturn server with dockerfile configuration?
  • How about the docker run in virtul machine best practice?
  • Nuget CA certificates error on a docker container of core
  • Install docker in vagrant
  • Couchbase Client Failure
  • How do I SSH into the boot2docker host vm that the Vagrant 1.6 Docker Provider sets up?
  • How to set subnet for Docker 1.9 overflow network?
  • Cannot replace the software source inside docker Ubuntu image
  • Liberty Admin Center shows Docker server as running while it is not
  • 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.