Home > Software design >  Xdebug 3.0 WSL2 and VSCode - address is already in use by docker-proxy
Xdebug 3.0 WSL2 and VSCode - address is already in use by docker-proxy

Time:05-23

My VSCode in WSL:Ubuntu is unable to listen to the xdebug port, because it is blocked by some docker-proxy. I was following this Solution, but trying VSCode to listen to the xdebug port, results in the following error: Error: listen EADDRINUSE: address already in use :::9003

Can anyone help with connecting VSCode to xdebug?

Windows 11 says the port is already allocated by wslhost:

PS C:\WINDOWS\system32> Get-Process -Id (Get-NetTCPConnection -LocalPort 9003).OwningProcess

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    285      47     2288       4748       0,05  19480   1 wslhost

Ubuntu tells, its allocated by some docker-proxy:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:9003            0.0.0.0:*               LISTEN      17210/docker-proxy
tcp6       0      0 :::9003                 :::*                    LISTEN      17217/docker-proxy

docker-compose-version: docker-compose version 1.25.0

The xdebug.log says:

[Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[Step Debug] ERR: Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(

For shure as long as nothing is listening.

As to xdebug.client_host I'v tried:

Removing the Expose directive from Dockerfile/docker-compose as in this comment doesn't remove the error neither.

CodePudding user response:

Solved it. For others with this challenge:

Inside of wsl-ubuntu -> docker-containter host.docker.internal directs to the wrong ip. In the wsl-distribution the file /etc/resolv.conf is the ip of the windows host. To get the correct ip use this answer: How to get the primary IP address of the local machine on Linux and OS X?

My solution is to define an env-variable with this ip:

alias docker_compose_local_ip="ifconfig eth0 | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'"
export DOCKER_COMPOSE_LOCAL_IP=$(docker_compose_local_ip)

and configure the container with it:

services:
  service-name:
    environment:
      - XDEBUG_CONFIG=client_host=${DOCKER_COMPOSE_LOCAL_IP} ...
  • Related