Docker - port prevents listening

岁酱吖の 提交于 2019-12-23 04:43:40

问题


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


回答1:


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.




回答2:


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:


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.



回答4:


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"


来源:https://stackoverflow.com/questions/38114976/docker-port-prevents-listening

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!