简体   繁体   English

Docker容器与网关的连接被拒绝

[英]Docker container connection to gateway refused

While setting up a php dev environment with docker, I ran into an issue while setting up remote debugging (XDEBUG) through a dbgp proxy. 在使用docker设置php开发环境时,通过dbgp代理设置远程调试(XDEBUG)时遇到了问题。

Connecting my host machine to the proxy doesn't seem to be a problem, but the proxy container cannot reach my host machine over the port that is configured (in this case 9003) 将我的主机连接到代理似乎没有问题,但是代理容器无法通过配置的端口(在这种情况下为9003)到达我的主机。

I'm using docker compose on windows. 我在Windows上使用docker compose。

Sucessfully connecting my dev machine to the proxy: 成功将我的开发机连接到代理:

INFO: dbgp.proxy: Server:onConnect ('172.18.0.1', 36558) [proxyinit -p 9003 -k XDEBUG_IDEA -m 1 ]

When executing a request containing the right IDE key (eg http://localhost/?XDEBUG_SESSION_START=XDEBUG_IDEA ), the proxy reacts correctly but is unable to contact the gateway over the port that was registered by my dev machine) 当执行包含正确的IDE密钥的请求时(例如, http:// localhost /?XDEBUG_SESSION_START = XDEBUG_IDEA ),代理正确响应 ,但无法通过我的开发机注册的端口与网关联系。

INFO: dbgp.proxy: connection from 172.18.0.2:40902 [<__main__.sessionProxy instance at 0x7fcff1998998>]
ERROR: dbgp.proxy: Unable to connect to the server listener 172.18.0.1:9003 [<__main__.sessionProxy instance at 0x7fcff1998998>]
Traceback (most recent call last):
  File "/usr/local/bin/pydbgpproxy", line 223, in startServer
    self._server.connect((self._serverAddr[0], self._serverAddr[1]))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 111] Connection refused
WARNING: dbgp.proxy: Unable to connect to server with key [XDEBUG_IDEA], stopping request [<__main__.sessionProxy instance at 0x7fcff1998998>]
INFO: dbgp.proxy: session stopped

Any ideas on what is going wrong here? 对这里出什么问题有任何想法吗? Firewall issues can be excluded here, since i basically just turned it of. 防火墙问题可以在这里排除,因为我基本上只是把它关掉了。

I did log into the dbgpproxy container and was able to send requests to the gateway ip over ports 80 an 8080, but got the same connection refused when trying port 9003) 我确实登录到dbgpproxy容器,并且能够通过端口80和8080向网关ip发送请求,但是尝试使用端口9003时却拒绝了相同的连接)

Any pointers would be greatly appreciated! 任何指针将不胜感激!

The docker compose file: 泊坞窗撰写文件:

version: '2'

volumes:
  mysqldata:
    driver: local

services:

  app:
      restart: "always"
      image: php:7.0-fpm
      command: "true"
      volumes:
          - .:/var/www/html

  nginx:
      restart: "always"
      build: ./docker/nginx/
      ports:
          - "80:80"
      depends_on:
          - php

  php:
      restart: "always"
      build: ./docker/php/
      environment:
          XDEBUG_CONFIG: remote_host=dbgpproxy
      expose:
          - "9000"
      depends_on:
          - mysql
      volumes_from:
          - app

  composer:
    restart: "no"
    image: composer/composer:php7
    command: install
    volumes:
      - .:/app

  dbgpproxy:
    restart: "always"
    image: christianbladescb/dbgpproxy
    expose:
        - "9000"
    ports:
        - "9001:9001"
    environment:
        DOCKER_HOST: 10.0.75.1

  mysql:
      image: mysql:latest
      volumes:
          - mysqldata:/var/lib/mysql
      environment:
          MYSQL_ROOT_PASSWORD: secret
          MYSQL_DATABASE: project
          MYSQL_USER: project
          MYSQL_PASSWORD: project

  phpmyadmin:
      image: phpmyadmin/phpmyadmin
      ports:
          - 8080:80
      depends_on:
          - mysql
      environment:
          PMA_HOST: mysql

  redis:
    image: redis
    ports:
      - "6379:6379"

  mailcatcher:
      image: schickling/mailcatcher
      restart: "always"

Docker network info: Docker网络信息:

[
    {
        "Name": "test_default",
        "Id": "8f5b2e1188d65948d6a46977467b181e7fdb4b112a688ff87691b35c29da8970",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Containers": {
            "05725540eca07666de250f2bb9ae856da69c0c325c4476150f214ba32a9b8714": {
                "Name": "test_nginx_1",
                "EndpointID": "723a820ea07e77cf976712293a911be3245e862477af6e0ecdcc1462536de6f5",
                "MacAddress": "02:42:ac:12:00:08",
                "IPv4Address": "172.18.0.8/16",
                "IPv6Address": ""
            },
            "78085ebed911e767a9c006d909cb245e0392055d37550c6cfa3a618969bef821": {
                "Name": "test_dbgpproxy_1",
                "EndpointID": "2332e1a01a8c0ec7262d96829d7d8f3cb4c711b6e9033ab85a8dfdb57ae01382",
                "MacAddress": "02:42:ac:12:00:0a",
                "IPv4Address": "172.18.0.10/16",
                "IPv6Address": ""
            },
            "7e12ea0a3a9b90360be6c15222fd052fbf02065aa18b8a3b12d19779bef4b41b": {
                "Name": "test_phpmyadmin_1",
                "EndpointID": "456a6508b6a507e01584beaf54eec9605db449261749065a562a6fb62111bb9c",
                "MacAddress": "02:42:ac:12:00:05",
                "IPv4Address": "172.18.0.5/16",
                "IPv6Address": ""
            },
            "81043a642cd9932e16bc51ba4604f6057d82e2c05f6e7378a85adfaa2de87f28": {
                "Name": "test_app_1",
                "EndpointID": "cfa41a5f210d4907747dcf7d516c6bdaecb817c993867a1e5f8e0250d33c927b",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            },
            "8b0cd7dc33fb783ae811f7ba15decd0165199da66242a10a33d8ee86c41bd664": {
                "Name": "test_mailcatcher_1",
                "EndpointID": "f2ed38e42dffd9565822a7ac248dcb022a47c8a78b05e93793b62d7188d0823c",
                "MacAddress": "02:42:ac:12:00:06",
                "IPv4Address": "172.18.0.6/16",
                "IPv6Address": ""
            },
            "d552bf1ab3914220b8fbf9961cc3801acbe180c6e945bd0b4c3bcf8588352a5d": {
                "Name": "test_mysql_1",
                "EndpointID": "6188cbeb49cf8afc2a7622bd6ef7fc7076ea91b909ec3efc1d9a1ed1d35d5790",
                "MacAddress": "02:42:ac:12:00:04",
                "IPv4Address": "172.18.0.4/16",
                "IPv6Address": ""
            },
            "ecc941fc337d727e3c118bf9112dee1552ef5db7c94b24706c7d03bc42ea6c0a": {
                "Name": "test_redis_1",
                "EndpointID": "3f4254982ed1be8354f514dd717993e02b4afdfad8d022f5f8daf0b919a852e1",
                "MacAddress": "02:42:ac:12:00:07",
                "IPv4Address": "172.18.0.7/16",
                "IPv6Address": ""
            },
            "f15f53405205db7263013fbb1ef1272764ca16850a46097b23d3619cd3d37b20": {
                "Name": "test_php_1",
                "EndpointID": "5fe30610823cd5660bf62e7612007ff4eef0316cbdfd15dbc0e56cafa6a3aca7",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

That's because pydbgpproxy works similar to XDebug and it is trying to connect to the wrong IP address. 那是因为pydbgpproxy的工作方式类似于XDebug,并且它正在尝试连接到错误的IP地址。 The correct IP address pydbgpproxy should connect to is host.docker.internal. pydbgpproxy应该连接的正确IP地址是host.docker.internal。

Situation: xDebug ---> pydbgpproxy -X-> Host

This is because pydbgpproxy received the wrong IP from Docker in the first place. 这是因为pydbgpproxy首先从Docker接收到错误的IP。 So I guess you have to hardcode the host.docker.internal IP into pydbgpproxy 所以我想你必须将host.docker.internal IP硬编码为pydbgpproxy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM