Getting setup and running with Xdebug in a docker container these days is now fairly simple and is composed of two main steps:
-
Ensure you've got XDebug installed and enabled in your PHP docker image, for example:
RUN pecl install xdebug \ && docker-php-ext-enable xdebug \Note: This example is extremely generic and should work in most of the official PHP docker container images, especially if you've ensured that you have also installed phpize (necessary for building PHP extensions).
-
Ensure the
remote_hostis referencinghost.docker.internal(Docker for Windows or Docker for Mac circa 18.03 and later, see docs: Windows and Mac) or10.0.2.2for VirtualBox when using Docker Toolbox. For example, here's part of myxdebug.ini:; Allow remote hosts to enable debugging, causing Xdebug to explicitly connect back to the workstation that Docker is running on. [XDebug] xdebug.remote_enable = true xdebug.remote_host = host.docker.internal ; Or, for workstations using Docker Toolbox (VirtualBox), use: ;xdebug.remote_host = 10.0.2.2
Note that these examples are highly simplified. See files below for more detailed example code.
Thanks for the simple, clutter free, example!