I have a Docker Compose stack running on a cloud server. One of the services is PHP with Xdebug.
When I run the stack on my local machine, I can use Xdebug just fine. But when I run it on the remote cloud server, no matter how I configure things, I can't seem to get Xdebug to connect back to my local IDE.
I've tried changing various Xdebug settings (discover_client_host
etc.) but nothing seems to work.
My latest attempt is as follows:
- From
docker-compose.yml
:
[...]
environment:
- XDEBUG_MODE=debug
- XDEBUG_CONFIG=discover_client_host=On
ports:
- 9003:9003
[...]
networks:
internal:
driver: bridge
- When I run
docker compose up
on the cloud server I can see that exposes port 9003:
sudo netstat -nlp | grep 9003
tcp 0 0 0.0.0.0:9003 0.0.0.0:* LISTEN 2119936/docker-prox
tcp6 0 0 :::9003 :::* LISTEN 2119943/docker-prox
- So then I try to create a port forward via an SSH tunnel from my local machine like this:
ssh -R 9003:localhost:9003 username@cloudhost.com
But I get an error: Warning: remote port forwarding failed for listen port 9003
presumably because port 9003 is already in use.
But if that's the case, how can I ever access port 9003 inside the Docker container from my local machine?