Geting the private ip for the docker network from within the container to configure xdebug remote_host
The host can be accessed from within the container using the IP address of the default gateway (that is the IP of the docker0
network interface on host). Use ip
to get it:
ip route show default | awk '/default/ {print $3}'
How to get the IP address of the docker host from inside a docker container
/sbin/ip route|awk '/default/ { print $3 }'
As @MichaelNeale noticed, there is no sense to use this method in Dockerfile
(except when we need this IP during build time only), because this IP will be hardcoded during build time.
Setting up XDebug with Docker and VSCode
Xdebug 3 has changed the names of settings. Instead of xdebug.remote_host
, you need to use xdebug.client_host
, as per the upgrade guide: https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_host
xdebug.remote_connect_back
has also been renamed in favour of xdebug.discover_client_host
, but when using Xdebug with Docker, you should leave that set to 0
.
Xdebug inside Docker on Mac M1 2021 is not working
Solution for running phpunit (or any cli script) in debug mode via
The configuration inside your docker running container at
/etc/php8/conf.d/50_xdebug.ini
needs to be like below
zend_extension=/usr/lib/php8/modules/xdebug.so
xdebug.mode=debug
xdebug.idekey=PHPSTORM
xdebug.client_port=9001
xdebug.start_with_request=yes
xdebug.discover_client_host=0
xdebug.client_host=host.docker.internal
xdebug.log=/var/log/xdebug.log
but that is not enough.
You have to set manually the Configuration Option in the interpreter for
xdebug.client_host
to equal host.docker.internal
inside PhpStorm interpreter configuration
This is somehow ignored and not read from the config file /etc/php8/conf.d/50_xdebug.ini
during cli mode and I was having issue for tests debug not working while web http requests were working fine.
Related Topics
MySQL Code Causes PHP Script to Crash at Popen/Exec
Send Cookie with File_Get_Contents
Doctrine Query Language Get Max/Latest Row Per Group
Upload a File Using File_Get_Contents
How to Get Ssl Certificate Info with Curl in PHP
PHP JSON Encode - Malformed Utf-8 Characters, Possibly Incorrectly Encoded
Destroy PHP Session on Closing
How to Read Cookie/Session Value While Executing PHP5 Script Through Command Prompt
Do Login Forms Need Tokens Against Csrf Attacks
How to Enable Memcache in Wamp
Simple HTML Dom: How to Remove Elements
Is Include()/Require() with "Side Effects" a Bad Practice
How to Build a JSON Array from MySQL Database
When Will _Destruct Not Be Called in PHP
Pdo: MySQL Server Has Gone Away