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_host
is referencinghost.docker.internal
(Docker for Windows or Docker for Mac circa 18.03 and later, see docs: Windows and Mac) or10.0.2.2
for 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 for PHP 7.3 and below. However, starting with PHP 7.4, the
pecl
command 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).
Very welcome @ericjeker! Just wanted to boil it down to bare necessities, since everyone is going to have their own needs.