Using Xdebug in Docker
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
host.docker.internal(Docker for Windows or Docker for Mac circa 18.03 and later, see docs: Windows and Mac) or
10.0.2.2for VirtualBox when using Docker Toolbox. For example, here's part of my
; 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!
- 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
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).