Geting the Private Ip for the Docker Network from Within the Container to Configure Xdebug Remote_Host

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

Sample Image

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



Leave a reply



Submit