Docker – port prevents listening

I am trying to setup xdebug integration on my docker-based setup.

I must precise that I’m a newbie in networks..

  • Accessing apache2 residing inside Docker container from Host machine web browser
  • Where does the output for “docker -build” go?
  • SSH into a DC/OS created public agent node to deploy a Docker container?
  • How do I run Docker on Google Compute Engine?
  • docker makes port of container open to public
  • How do I properly use Silex 2, Doctrine, and PDO via docker containers?
  • 3 Solutions collect form web for “Docker – port prevents listening”

    It dependent how you want to connect via Xdebug

    xdebug.remote_connect_back=1 said that PHP will wait until a HTTP request with GET parameter XDEBUG_SESSION_START=<IDE_key>. Then will PHP within the server try to connect back via port 9000 where your PHPStorm is listing. Classic don’t call us, we will call you situation.

    Now your situation with docker say simple, your container is responsible for port 9000. So PHP will get a loopback and PHPStorm isn’t able to use port 9000 because its already used by your docker container.

    So skip the assignment of port 9000 to docker, that will fix this situation.

    Firstly check your container logs to debug:

    docker logs 6950c2a2b05d
    

    or

    docker logs app_1
    

    Add -f flags for tail-like behavior:

    docker logs -f app_1
    

    Two things I discovered:

    • There is no need to expose the port 9000 on a container with xdebug (that seems rather counter-intuitive for me, as I do not exactly understand how my IDE connects to xdebug then).
    • I was able to use xdebug using the workaround described in https://forums.docker.com/t/ip-address-for-xdebug/10460/4.
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.