John Davidson

php - xDebug + DBGpProxy in a docker webserver stack

0 comments
Message:


I'm trying to setup DBGpProxy in a docker container within my dev-webserver stack for multiuser debugging.
The Problem is, that I can't get the proxy connect to the container where xdebug is running.


First my config, then the problem


Here is my docker-compose.yml:


version: "3.9"

services:

webserver:
container_name: apache_webserver
build: builds/apache
restart: always
volumes:
- ./www:/var/www/html
- ./logs:/var/log/
- ./builds/apache/php-ini-overrides.ini:/usr/local/etc/php/conf.d/php-ini-overrides.ini
expose:
- "80"
ports:
- 9003:9003
labels:
- "traefik.enable=true"
- "traefik.http.routers.webserver.entrypoints=http"
- "traefik.http.routers.webserver.rule=Host(`dev.mydomain.local`)"
networks:
- traefik_proxy
- default

dbgpproxy:
container_name: apache_dbgpproxy
build: builds/dbgpproxy
restart: always
ports:
- 9100:9100
networks:
- traefik_proxy
- default

database:
container_name: apache_mariadb
image: mariadb:latest
restart: always
volumes:
- ./db:/var/lib/mysql
ports:
- 3306:3306
environment:
- MYSQL_USER=user_sql
- MYSQL_PASSWORD=some_pwd
- MYSQL_ROOT_PASSWORD=some_root_pwd

networks:
traefik_proxy:
external: true
name: traefik_proxy
default:
driver: bridge

and here is the Dockerfile for the proxy:


FROM debian

RUN apt-get update
RUN apt-get -y install wget

RUN wget -O /var/dbgpProxy https://xdebug.org/files/binaries/dbgpProxy
RUN chmod 0777 /var/dbgpProxy
RUN chmod +x /var/dbgpProxy

CMD /var/dbgpProxy -i 0.0.0.0:9100 -s 127.0.0.1:9003

the php.ini has these settings:


[xdebug]
zend_extension=xdebug.so
xdebug.mode=debug,develop
xdebug.client_host=host.docker.internal
xdebug.client_port=9003

Docker is running on a (virtualBox) Ubuntu 20.04 Server.Xdebug DBGp proxy Version is 0.3, xDebug is 3.1.0. Docker version 20.10.9, docker-compose version 1.29.2




I have no problem, when I got the dbgpProxy running directly on the Ubuntu (IP: 192.168.0.13).


PHP.ini config:
xdebug.client_host=192.168.0.13


dbgpProxy call:
sudo ./dbgpProxy -i 192.168.0.13:9100 -s 192.168.0.13:9003


docker-compose.yml:
same as bevor, but port 9003 isn't published and without the dbgpproxy service (of course :-)


With this config I can debug smoothly.




Now to the Problem:
As soon As I try to get the dbgpproxy running within the stack I can register my IDE with it, but it does not receive any data from the webserver container.
It seems like my main problem is, that I can't find a way how to connect from one container to another.


I can only bind ports to the dbgpProxy if I use one of these IPs:
localhost, 127.0.0.1, 0.0.0.0 (and if I remember right, the apache_dbgpproxy container's IP). In all other (usefull) cases, like when I try to bind the port on the apache_webserver internal IP, I get errors like this:


panic: listen tcp 192.168.48.3:9003: bind: cannot assign requested address

things like host.docker.internal are resolved to the correct (internal) IP of the container, but I'm not allowed to bind them. Same goes for the Ubuntu's IP. I can ping any IP in the networks. Even docker hostnames like apache_webserver are resolved fine.


Due to any documentation I found all you need is a computer which can access the xdebug's clients and the server, which I can (at least ping them), s I dont see the problem, why I can't bind anything elsem, but the container itself. Beside: even the ubuntu can only bind itself, but there it is at least no problem.


But how do I get the dbgpproxy container talking with the webserver container?



My Answer:
3
services:
webserver:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./src:/var/www/html
php:
image: php:7.4-fpm
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
environment:
XDEBUG_CONFIG: remote_host=host.docker.internal remote_port=9001
xdebug:
image: php:7.4-fpm
command: php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1 -dxdebug.remote_port=9001 -dxdebug.remote_host=host.docker.internal -S 0.0.0.0:9001
volumes:
- ./src:/var/www/html

And here is my DBGpProxy config in .vscode/launch.json:

{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9001,
"pathMappings": {
"/var/www/html": "${workspaceFolder}"
}
}
]
}

The problem is that when I start the DBGpProxy in my container, it can't connect to the xdebug running in the xdebug container. I've tried different configurations for the remote_host in the xdebug container, but nothing seems to work.

Any help would be greatly appreciated.

Rate this post

5 of 5 based on 5664 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us