question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

I am having an issue related to https://github.com/martomo/SublimeTextXdebug/issues/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 <jmacias@solidgear.es>

# 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.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
jashkcommented, Aug 15, 2016

You don’t need expose 9000 port, just remove from setup - “9000:9000” & EXPOSE 9000 .

1reaction
8ctopuscommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Address Already in Use" When Starting a Docker Instance
This issue can happen when for any reason your host reboots. In this instance, try restarting your apache server. Stopping apache2 service in ......
Read more >
Docker Error bind: address already in use - Stack Overflow
Run docker ps to see list of all containers running under your host. If you find the port is in use by another...
Read more >
0001877: Xdebug from docker container can't connect to client
I try to use new Xdebug on my laptop T490 with KDE Neon and PhpSorm. Project runs on few docker containers (below config...
Read more >
listen EADDRINUSE: address already in use :::9000
Listening to Xdebug on port 9000 failed: Error: listen EADDRINUSE: address already in use :::9000. A popup directs me to launch.json.
Read more >
Docker Error Bind: Address Already in Use | Baeldung on Linux
To resolve the issue, first, we need to reproduce the problem. Assume that port 8080 on the Docker host machine is already occupied....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found