Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Errno 98] Address already in use when listening to port 9000 from xdebug in a docker container #162

Open
wesleymusgrove opened this issue May 24, 2016 · 6 comments

Comments

@wesleymusgrove
Copy link

I am having an issue related to #63. Closing down multiple Sublime windows did not fix it for me.

See @trungdq88's post: http://stackoverflow.com/questions/35532325/docker-port-conflict-on-ubuntu/35532956 for a detailed explanation on why Sublime cannot listen to port 9000, 9001, or whichever port you are trying to listen for xdebug.

I also receive the following error in Sublime: "Xdebug Client.xdebug.protocol.ProtocolConnectionException: [Errno 98] Address already in use" because the docker-proxy process is already listening to port 9000.

Host:

  • Ubuntu 14.04 LTS
  • Sublime Text 3, Build 3059
  • Installed SublimeTextXdebug with Package Control.

SublimeTextXdebug User Settings:

{
  "path_mapping": {
    "/var/www/example/docroot/" : "/srv/example/public_html/example/docroot/"
  },
    "url": "http://www.example.local/",
    "port": 9000,
    "close_on_stop": true,
    "pretty_output": true,
    "launch_browser": true,
    "debug": true
}

Guest:

  • Docker container

20-xdebug.ini:

zend_extension = /usr/lib/php5/20121212/xdebug.so
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/tmp"
xdebug.default_enable=1
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=172.17.42.1
xdebug.remote_port=9000
xdebug.idekey="sublime.xdebug"
xdebug.remote_connect_back=1
xdebug.remote_log=/tmp/xdebug.log

docker-compose.yml:

www:
  image: httpd:2.4
  ports: 
    - "80:80"
    - "9000:9000"
  environment:
    XDEBUG_CONFIG: "remote_host=172.17.42.1 remote_port=9000 idekey=sublime.xdebug"
  volumes:
    - public_html:/var/www

Dockerfile:

FROM httpd:2.4
MAINTAINER Jesus Macias Portela <[email protected]>

# Install xdebug
RUN apt-get purge \
 && apt-get update \
 && apt-get install -y php5-xdebug

# Add Xdebug configuration
ADD 20-xdebug.ini /etc/php5/apache2/conf.d/20-xdebug.ini

EXPOSE 80
EXPOSE 9000

Output of tmp/xdebug.log:
It immediately closes as soon as it connects to the client

Log opened at 2016-05-20 14:19:10
I: Checking remote connect back address.
I: Remote address found, connecting to 10.12.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/example/docroot/index.php" language="PHP" protocol_version="1.0" appid="10" idekey="sublime.xdebug"><engine version="2.2.3"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2013 by Derick Rethans]]></copyright></init>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

Log closed at 2016-05-20 14:19:12

Output of Sublime Text console:

Traceback (most recent call last):
  File "./threading.py", line 901, in _bootstrap_inner
  File "./threading.py", line 858, in run
  File "main in /home/example/.config/sublime-text-3/Installed Packages/Xdebug Client.sublime-package", line 275, in listen
  File "xdebug.protocol in /home/example/.config/sublime-text-3/Installed Packages/Xdebug Client.sublime-package", line 250, in listen
Xdebug Client.xdebug.protocol.ProtocolConnectionException: [Errno 98] Address already in use

As shown in the above mentioned StackOverflow issue, changing the HOST:CONTAINER port mapping to something like 12345:9000 doesn't work because on the HOST the docker-proxy process listens to port 12345 and Sublime still cannot listen to port 12345 because it's already in use.

Is there some way for Sublime to listen to port 9000 even if another process is also listening on that port?

As far as I can see, this is like an infinite circle of doom, where Sublime will never be able to listen to xdebug requests coming from a docker container because of the docker-proxy service running on the same port that Sublime needs to be listening to on the host.

@joemewes
Copy link

confirmed. I also can't see how this site an issue on ALL Xdebug setups using docker. so maybe we're missing something?

@joemewes
Copy link

@wesleymusgrove I got this working from my docker container to HOST using docker for mac https://gist.github.com/ralphschindler/535dc5916ccbd06f53c1b0ee5a868c93

I'm not 100% sure why, but seems its possible to hookup guest & host without the requirements for the PORT assignments, so removing the hardcoded ports in the docker-compose (run command) will free up your IDE to listen. more discussion needed i think... but FYI ^^^

@jashk
Copy link

jashk commented Aug 15, 2016

You don't need expose 9000 port, just remove from setup - "9000:9000" & EXPOSE 9000 .

@8ctopus
Copy link

8ctopus commented Apr 1, 2020

For those having problems enabling remote debugging from a docker container (like I had for about 5 hours), here's a config that works without changes:

xdebug.remote_enable=1
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9000
xdebug.remote_mode=req
xdebug.remote_autostart=0
xdebug.remote_connect_back=0

In sublime text 3, use these settings:

"path_mapping": {
    "/var/www/site/" : "K:/dev/github/php-dev/dev/",
},
"ide_key": "sublime.xdebug",
"host": "127.0.0.1",
"port": 9000,

Adjust the path_mapping to your situation and make sure your docker-compose does not map port 9000:9000 at all as otherwise it won't work. Here's a docker example.

Also I think the issue can be closed as it's clearly a docker issue and not the plugin.

@serverjohn
Copy link

@8ctopus I am having the same problem and I am trying to apply your configurations. However, I am a total docker newb. Where does the following go?

xdebug.remote_enable=1
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9000
xdebug.remote_mode=req
xdebug.remote_autostart=0
xdebug.remote_connect_back=0

@8ctopus
Copy link

8ctopus commented Mar 25, 2021

@serverjohn within the docker container /etc/php7/conf.d/. Look for the xdebug.ini config file. In my case the name is 50_xdebug.ini. You may want to checkout the docker container I built as it all works out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants