Docker容器连接网关被拒绝。

3

在使用docker搭建php开发环境时,我在设置远程调试(XDEBUG)通过dbgp代理时遇到了问题。

连接我的主机到代理似乎没有问题,但是代理容器无法通过配置的端口(在这种情况下为9003)访问我的主机。

我正在windows上使用docker compose。

成功将我的开发机连接到代理:

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

当执行包含正确IDE key的请求时(例如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

这里出了什么问题,有什么想法吗? 由于我基本上只是关闭了防火墙,所以可以排除防火墙问题。

我登录到dbgpproxy容器,并能够通过端口80和8080向网关IP发送请求,但在尝试端口9003时仍然遇到相同的连接拒绝错误。

任何指针都将不胜感激!

Docker Compose文件:

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网络信息:

[
    {
        "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": {}
    }
]

可能与问题相关:https://github.com/docker/for-win/issues/37 - Bert
1个回答

0
那是因为pydbgpproxy的工作方式类似于XDebug,它试图连接到错误的IP地址。pydbgpproxy应该连接到的正确IP地址是host.docker.internal。
情况如下: xDebug ---> pydbgpproxy -X-> 主机
这是因为pydbgpproxy首先从Docker接收到了错误的IP地址。 所以我猜你需要在pydbgpproxy中硬编码host.docker.internal的IP地址。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接