Docker - port prevents listening

2019-06-14 02:39发布

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

  • I am using Docker for Mac 1.12.0-rc2-beta17 with the "native" docker machine
  • I have a container, with xdebug installed, exposing port 9000 and mapping it to the port 9000:

    $ docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                      NAMES
    6950c2a2b05d        app        "/usr/bin/supervisord"   9 minutes ago       Up 9 minutes        0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:9000->9000/tcp, 0.0.0.0:2222->22/tcp   app_1
    
  • When I'm trying to use PhpStorm to listen to the port 9000 for debug connections, I'm getting an error "Cannot listen: port 9000 is busy".

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

4条回答
来,给爷笑一个
2楼-- · 2019-06-14 02:49

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
查看更多
叼着烟拽天下
3楼-- · 2019-06-14 02:55

You must bind 9000 port with --expose option.

This is the reference

if you are using docker compose sample docker-compose.yml file is here:

version: '2'
    services:
      your_app:
         ports:
         - "80:80"
         expose:
         - "9000"
         image: "your-image:tag"
查看更多
劫难
4楼-- · 2019-06-14 02:59

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.

查看更多
劳资没心,怎么记你
5楼-- · 2019-06-14 03:07

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.
查看更多
登录 后发表回答