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:
# Installing Xdebug with PHP 7.3 images: RUN pecl install xdebug \ && docker-php-ext-enable xdebug \
-
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
For more detailed example code, please see the files below!
Notes:
- These examples are very generic and should work in most of the official PHP docker container images at for PHP 7.3 and below. However: Starting with PHP 7.4, the
peclcommand will no longer be available. See: Installing PHP extensions from source in your Dockerfile - For Alpine linux variants, ensure that you have also installed phpize (necessary for building PHP extensions).
Thanks for the simple, clutter free, example!