Works for me on Ubuntu 20.04.

Add to you project's docker-compose.yml

(https://github.com/docker/for-linux/issues/264#issuecomment-772844305)

services:
  your_php_service_name:
    extra_hosts:
      - host.docker.internal:host-gateway

In your CLI run export XDEBUG_TRIGGER=1 && export PHP_IDE_CONFIG="serverName=host.docker.internal" to start xdebug with the request.

Thanks @LazyOne for his comment to the question with the solution.

Answer from Yehor on Stack Overflow
🌐
Medium
medium.com › the-sensiolabs-tech-blog › how-to-use-xdebug-in-docker-phpstorm-76d998ef2534
How to use Xdebug in Docker & PhpStorm | The SensioLabs Tech Blog
June 14, 2022 - $ docker-compose up -d --build $ docker-compose exec app php -v PHP 8.1.6 (cli) (built: May 28 2022 08:14:41) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.6, Copyright (c) Zend Technologies with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans
🌐
Thecodingmachine
thecodingmachine.io › configuring-xdebug-phpstorm-docker
Debugging PHP (web and cli) with Xdebug using Docker and PHPStorm
For more details, please look at this TheCodingMachine Docker PHP images. ... (4) If you are using the default Xdebug port, please remove remote_port=[your_xdebug_port]. Otherwise, add your custom Xdebug port · Place a breakpoint in your code and launch a debug session · A new windows should open and you should access to PHPStorm debug bar. Click on Start Listening for PHP Debug connections
Discussions

Debug PHP cli application inside docker with PhpStorm - Stack Overflow
So one of the docker containers runs my php application, where the PHP interpreter lives. Before (when the application was exactly in Vagrant machine) I was using this command to debug my cli applications, but now it does not work.: export XDEBUG_CONFIG="remote_enable=1 remote_mode=req ... More on stackoverflow.com
🌐 stackoverflow.com
php - Installing XDebug in Docker - Stack Overflow
I'm trying to install the XDebug in a Docker container, but I'm getting the following error: E: Unable to locate package php-xdebug This is my Dockerfile: FROM php:7.0-apache RUN a2enmod rewrite ... More on stackoverflow.com
🌐 stackoverflow.com
Getting xdebug to work with my container
I’ve struggled to get a dev environment setup and running with a persistent database and with xdebug installed. I finally managed to get my container going with a persistent database and I did finally manage to get xdebug installed with my container. But I am still not getting xdebug to work ... More on forums.docker.com
🌐 forums.docker.com
17
0
March 9, 2024
php with xdebug: Unable to debug console PHP in Visual Studio Code when using podman (Works in Docker)
FROM docker.io/php:cli # Install xdebug for nicer error messages RUN pecl install xdebug RUN docker-php-ext-enable xdebug More on reddit.com
🌐 r/podman
2
2
April 17, 2024
🌐
GitHub
gist.github.com › chadrien › c90927ec2d160ffea9c4
Debug PHP in Docker with PHPStorm and Xdebug · GitHub
For your local dev, create a Dockerfile that is based on your production image and simply install xdebug into it. Exemple: FROM php:5 RUN yes | pecl install xdebug \ && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \ && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
🌐
GitHub
github.com › Crix4lis › docker-php-cli-xdebug
GitHub - Crix4lis/docker-php-cli-xdebug: Provides basic php-cli docker image with installed Composer and configured xDebug along with PHPStorm IDE configuration manual. Use it as starting point to your custom PHP application based on whatever you want, like Symfony
July 30, 2021 - Provides basic php-cli docker image with installed Composer and configured xDebug along with PHPStorm IDE configuration manual. Use it as starting point to your custom PHP application based on what...
Starred by 5 users
Forked by 2 users
Languages   Shell 74.2% | Dockerfile 25.8% | Shell 74.2% | Dockerfile 25.8%
🌐
DEV Community
dev.to › jackmiras › xdebug-in-phpstorm-with-docker-2al8
Xdebug in PhpStorm with Docker - DEV Community
November 3, 2023 - Subsequently, click into Add New Configuration > PHP Remote Debug as the screenshot down below shows: Next, a form will open, and there, fill the Name with your Remote Debug configuration; next, check the Filter debug connection by IDE key option and then select the Server previously created; and finally, fill the IDE key (session id) with the same value that got used at the xdebug.idekey directive at our .docker/xdebug.ini.
🌐
Matthew Setter
matthewsetter.com › setup-step-debugging-php-xdebug3-docker
Setup Step Debugging in PHP with Xdebug 3 and Docker Compose | Blog - Matthew Setter. Accessible Web App Developer, Educator, and Author, based in Bundaberg, Queensland.
March 10, 2021 - client_host: This setting tells Xdebug the IP address or hostname of the machine that is running your text editor or IDE. start_with_request: This setting determines whether a function trace, garbage collection statistics, profiling, or step debugging are activated at the start of a PHP request. Setting it to yes instructs Xdebug to always initiate a debugging session. Then, in docker/php/conf.d/error_reporting.ini, add the following configuration, to enable full error reporting.
Find elsewhere
🌐
Blog by Sandro Keil
sandro-keil.de › blog › docker-php-xdebug-cli-debugging
Docker PHP Xdebug CLI debugging
January 22, 2018 - You have configured your path mappings and enabled listen for incomming Xdebug connections, then you can start the container with the following command from the root of your project. $ docker run --rm -it --volume $(pwd):/app -e PHP_IDE_CONFIG="serverName=application" prooph/php:7.1-cli-xdebug php [your file]
🌐
Keboola Tech Blog
500.keboola.com › xdebug-for-a-cli-app-in-docker-and-phpstorm
Xdebug for a CLI App in Docker (and PHPStorm)
September 16, 2022 - Having Xdebug in your app will give you 2 major benefits: ... I went through a lot of articles touching on the subject, many of them were outdated, focused on web applications or very confusing. They simply didn't lead to a working debugger in my setup: ... The application is based on a very simple Dockerfile. FROM php:7.1-cli WORKDIR /code RUN apt-get update && apt-get install -y \ git \ unzip \ --no-install-recommends && rm -r /var/lib/apt/lists/* RUN curl -sS https://getcomposer.org/installer | php \ && mv /code/composer.phar /usr/local/bin/composer COPY .
🌐
GitHub
gist.github.com › loru88 › 898fef61b3001a3c7cc11b5d0f3c99ce
Manually debug PHP CLI inside a Docker container using PHPStorm · GitHub
xdebug idekey=PHPSTORM or whatever is in the File | Settings | Languages & Frameworks | PHP | Debug | DBGp Proxy
🌐
Docker Hub
hub.docker.com › r › phpstorm › php-71-cli-xdebug
phpstorm/php-71-cli-xdebug - Docker Image
PHP 7.1 image with enabled XDebug 2.6.0 · Image · 2 · 1.5K · OverviewTags · Pre-configured Docker images. See docker-compose.yml for details. Invoke Help|Edit Custom VM Options, change -Djava.net.preferIPv4Stack=true to -Djava.net.preferIPv6Stack=true. Connect to the server via [::1]. ...
🌐
Docker Hub
hub.docker.com › r › mobtitude › php-xdebug
mobtitude/php-xdebug - Docker Image
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.
🌐
JetBrains
jetbrains.com › help › phpstorm › configuring-xdebug.html
Configure Xdebug | PhpStorm Documentation
If you are using Docker for Windows or Docker for Mac, you can set xdebug.client_host to host.docker.internal, which automatically resolves to the internal address of the host, letting you easily connect to it from the container. RUN pecl install xdebug \ && docker-php-ext-enable xdebug && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ && echo "xdebug.remote_host = host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
🌐
DevTools CLI
phase2.github.io › devtools › common-tasks › using-xdebug-with-phpstorm
Using Xdebug with PHPStorm - DevTools CLI Documentation
In your docker command or your docker-compose.yml manifest, ensure the environment variable PHP_XDEBUG="true".
🌐
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
Images from this repository are the solution for this issue, since they have installed and configured xdebug plugin. The only difference from the official Docker PHP images is that, the xdebug plugin is installed, configured and ready to use with modern IDEs like phpStorm.
Starred by 20 users
Forked by 8 users
Languages   Dockerfile 61.9% | Shell 31.6% | Makefile 3.7% | PHP 2.8%
🌐
Adobe Developer
developer.adobe.com › commerce › cloud-tools › docker › test › configure-xdebug
Configure Xdebug
Click the + to add a PHP Remote Debug server configuration. The project name is in grey at the top. Configure the following settings for the new server configuration: Name—Enter the name used for the serverName option from PHP_IDE_CONFIG value. By default, MCD uses this value: serverName=magento_cloud_docker · Host—Enter localhost. Port—Enter 80. Debugger—Select Xdebug...