RUN apk add --no-cache $PHPIZE_DEPS \
    && pecl install xdebug-2.9.2 \
    && docker-php-ext-enable xdebug  \
Answer from Tania Petsouka on Stack Overflow
🌐
GitHub
github.com › mobtitude › docker-php-xdebug
GitHub - mobtitude/docker-php-xdebug: Docker images with PHP and xdebug installed, configured and ready to debug and profile applications in modern IDEs. · GitHub
Q: Why images don't have specific PHP version like 7.2.2 but only major and minor version 7.2? A: It is because images in this repo have always the newest possible patch version of PHP based on official Docker PHP images. For example for mobtitude/php-xdebug:7.2-apache you can expect that it is always the newest PHP version available in official Docker Registry and it is automatically updated when official PHP Docker images are updated.
Starred by 20 users
Forked by 8 users
Languages   Dockerfile 61.9% | Shell 31.6% | Makefile 3.7% | PHP 2.8%
🌐
GitHub
github.com › sineverba › php74xc
GitHub - sineverba/php74xc: Docker image for PHP7.4 with Xdebug and Composer
Docker image for PHP7.4 with Xdebug and Composer. Contribute to sineverba/php74xc development by creating an account on GitHub.
Forked by 2 users
Languages   Makefile 67.3% | Dockerfile 32.7% | Makefile 67.3% | Dockerfile 32.7%
🌐
GitHub
github.com › JetBrains › phpstorm-docker-images › blob › master › php-74-apache-xdebug-30 › Dockerfile
phpstorm-docker-images/php-74-apache-xdebug-30/Dockerfile at master · JetBrains/phpstorm-docker-images
FROM php:7.4-apache · COPY ... docker-php-ext-install mysqli zip intl · RUN pecl install xdebug-3.0.3 · RUN docker-php-ext-enable xdebug ·...
Author   JetBrains
🌐
GitHub
gist.github.com › lelinhtinh › 968d64ddbdc59ad6ff28636d3ab3cd72
Docker - VSCode - XDebug - PHP 7.4 · GitHub
Docker - VSCode - XDebug - PHP 7.4. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › maciejslawik › docker-php-fpm-xdebug › blob › master › Dockerfile
docker-php-fpm-xdebug/Dockerfile at master · maciejslawik/docker-php-fpm-xdebug
RUN echo 'alias xon="mv /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini.off /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && kill -USR2 1"' >> ~/.bashrc · · # Change memory limit · RUN echo 'memory_limit = 2G ' >> /usr/local/etc/php/php.ini · · # Install Blackfire probe - no version for 7.4 available yet ·
Author   maciejslawik
🌐
GitHub
github.com › pavlakis › docker-xdebug
GitHub - pavlakis/docker-xdebug: Build Xdebug from pecl and pull it in as a docker layer
pavlakis/xdebug:2.4.1 · Each version is installed in a different folder: PHP 8.0 -> /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ PHP 7.4 -> /usr/local/lib/php/extensions/no-debug-non-zts-20190902/ PHP 7.3 -> /usr/local/lib/php/extensions/no-debug-non-zts-20180731/ PHP 7.2 -> /usr/local/lib/php/extensions/no-debug-non-zts-20170718/ PHP 5.6 -> /usr/local/lib/php/extensions/no-debug-non-zts-20131226/ Dockerfile ·
Author   pavlakis
Find elsewhere
🌐
GitHub
gist.github.com › patricknelson › 57ae24986cb13613314fb1f3c00a95d7
Using Xdebug in Docker (works with PhpStorm) · GitHub
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
🌐
GitHub
github.com › bytepark › docker-php7-xdebug
GitHub - bytepark/docker-php7-xdebug: Docker Image with PHP7 xdebug and some modules · GitHub
Docker Image with PHP7 xdebug and some modules. Contribute to bytepark/docker-php7-xdebug development by creating an account on GitHub.
Starred by 10 users
Forked by 3 users
🌐
GitHub
github.com › humbertodias › docker-php-apache-xdebug
GitHub - humbertodias/docker-php-apache-xdebug: Docker container with PHP, Xdebug and Apache2.
This is a docker project to create a container with PHP, Xdebug and Apache2.
Starred by 2 users
Forked by 2 users
Languages   PHP 62.1% | Dockerfile 37.9% | PHP 62.1% | Dockerfile 37.9%
🌐
GitHub
gist.github.com › yuklia › e495b0dffee21f1d0f0dbcf250a6eb35
Dockerfile based on php:7-fpm with xDebug · GitHub
Dockerfile based on php:7-fpm with xDebug · This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ·
🌐
Docker
hub.docker.com › layers › ekreative › php › 7.4-rc-xdebug › images › sha256-135f2844256cc490c838eda532de43f7d391869e618a498e22b7ba5a215538ed
Image Layer Details - ekreative/php:7.4-rc-xdebug
Welcome to the world's largest container registry built for developers and open source contributors to find, use, and share their container images. Build, push and pull.
🌐
GitHub
github.com › maciejslawik › docker-php-fpm-xdebug
GitHub - maciejslawik/docker-php-fpm-xdebug: Docker image: PHP-FPM with XDEBUG enabled.
The repository stores an image of PHP-FPM (5.6-7.4) with preconfigured XDEBUG for local development.
Starred by 25 users
Forked by 12 users
Languages   Dockerfile 100.0% | Dockerfile 100.0%
🌐
Docker Hub
hub.docker.com › r › oberd › php-7.4-apache
oberd/php-7.4-apache - Docker Image
Requires: the environment variable GITHUB_OAUTH_TOKEN to be set. ... This task is dependent upon the configure task being ran. It will run composer install. ... This task will configure the Xdebug remote host into the Xdebug config.
🌐
GitHub
github.com › angristan › php-xdebug-docker
GitHub - angristan/php-xdebug-docker: Debug PHP with Xdebug inside Docker. Tested with PhpStorm and VS Code. · GitHub
Debug PHP with Xdebug inside Docker. Tested with PhpStorm and VS Code. - angristan/php-xdebug-docker
Starred by 24 users
Forked by 12 users
Languages   Dockerfile 92.4% | PHP 7.6%
Top answer
1 of 2
10

Xdebug traffic wasn't finding it's way back to my host. When I entered the IP-address of my host machine in xdebug.remote_host, debugging worked but this was not ideal because my IP changes on every reboot. Luckily, Docker provides a way to obtain the host IP via a DNS-entry docker.for.win.localhost.

Edit:
Docker now has a platform-independent DNS-entry host.docker.internal.

I tried to use xdebug.remote_connect_back=1 which just responds to traffic from where it came but it wasn't working. Phpinfo() showed that REMOTE_ADDR was set to localhost. Localhost in this context points to the Docker PHP-container while it should point to our host IP. Important to know with this setting is that xdebug.remote_host in the .ini will be ignored.

From the Xdebug docs:

xdebug.remote_connect_back Type: boolean, Default value: 0, Introduced in Xdebug >= 2.1

If enabled, the xdebug.remote_host setting is ignored and Xdebug will try to connect to the client that made the HTTP request.

Here is the Dockerfile with the xdebug.ini configuration for the PHP Docker container that worked:

FROM php:7.1-fpm
ARG TIMEZONE

MAINTAINER Maxence POUTORD <[email protected]>

RUN apt-get update && apt-get install -y \
    openssl \
    git \
    unzip

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version

# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"

# Type docker-php-ext-install to see available extensions
RUN docker-php-ext-install pdo pdo_mysql

# install xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# relevant to this answer
RUN echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_host=docker.for.win.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

RUN echo 'alias sf="php app/console"' >> ~/.bashrc
RUN echo 'alias sf3="php bin/console"' >> ~/.bashrc

WORKDIR /var/www/free-energy/symfony


Edit:
I was messing around with XDebug quite a bit in this post.
Now I know your XDebug config doesn't have to be as big as I had back then.

xdebug.ini: (in your Docker PHP image).

zend_extension=xdebug.so

[Xdebug]
xdebug.remote_enable=true
xdebug.remote_port=9000
xdebug.remote_host=host.docker.internal
2 of 2
1

Add the remote_connect_back=on, so xdebug connects to the current visitor (using the REMOTE_ADDR system variable) instead of the remote_host which may change. You can try with remote_autostart=on too, to make sure this issue is not related with the browser itself.

Remember to configure the mapping in phpStorm as well, but it will tell you to do so anyway. Also make sure the IDE is listening to the debug session (small toggle in the debug toolbar). Good luck.