如何让xdebug在远程服务器上的Docker中工作

问题描述 投票:1回答:1

所以,我花了大约两天时间,无法让xdebug在远程服务器上的容器(docker-compose config)中工作

我总是得到E: Time-out connecting to the client. :-(

Dev machine:

  • Win10与动态IP
  • 所有代码都是与远程服务器实时同步(通过“部署”功能)
  • PhpStorm配置为侦听端口9001,“侦听PHP调试连接”已启用。
  • 没有服务器等,只需零配置调试会话。

Remote server:

xdebug配置:

xdebug.remote_enable=1
xdebug.remote_port=9001
xdebug.remote_log="/var/www/xdebug.log"
xdebug.remote_connect_back=1

php-fpm,jwilder / nginx-proxy,letsencrypt-companion,nginx,jeroenpeeters / docker-ssh通过docker-compose运行。

这是docker-compose.yml的简化版本:

version: "2"

networks:
  default:
    external:
      name: nginx-proxy

services:

  nginx-proxy:
    container_name: nginx-proxy
    image: jwilder/nginx-proxy
    ports:
    - "80:80"
    - "443:443"
    volumes:
    - /var/run/docker.sock:/tmp/docker.sock:ro
    - ./secured/certs_letsencrypt:/etc/nginx/certs:ro
    - /etc/nginx/vhost.d
    - /usr/share/nginx/html
    restart: always

  letsencrypt-companion:
    container_name: letsencrypt-companion
    image: jrcs/letsencrypt-nginx-proxy-companion
    volumes:
    - ./secured/certs_letsencrypt:/etc/nginx/certs:rw
    - /var/run/docker.sock:/var/run/docker.sock:ro
    volumes_from:
    - nginx-proxy
    restart: always

  my_project_nginx:
    container_name: my_project_nginx
    build:
      context: ./containers/nginx_ssl
      args:
        appcontainer: my_project_app
        domain: example.com
    depends_on:
    - nginx-proxy
    links:
    - my_project_app
    - nginx-proxy
    environment:
    - VIRTUAL_HOST=example.com
    - LETSENCRYPT_HOST=example.com
    - [email protected]
    restart: always

  my_project_app:
    container_name: my_project_app
    build:
      context: .
      dockerfile: ./containers/php7_1/Dockerfile
      args:
        idrsafile: ./secured/id_rsa_shared
        php_memory_limit: 6G
    depends_on:
    - nginx-proxy
    restart: always

  my_project_ssh:
    container_name: my_project_ssh
    image: jeroenpeeters/docker-ssh
    depends_on:
    - my_project_app
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock
    - ./secured/authorized_keys:/authorized_keys
    ports:
    - "2227:22"
    environment:
    - FILTERS={"name":["my_project_app"]}
    - AUTH_MECHANISM=publicKey
    - AUTHORIZED_KEYS=/authorized_keys
    restart: always 

The problem

还有xdebug日志:

... 
I: Checking remote connect back address.
I: Remote address found, connecting to 5.18.238.83:9001.
E: Time-out connecting to the client. :-(

我尝试了很多变种(指定xdebug.remote_host,通过Putty建立SSH隧道等)仍然没有结果。

php docker docker-compose phpstorm xdebug
1个回答
0
投票

默认情况下,docker容器位于隔离网络(网络模式桥)中,出于安全原因不允许访问主机。

如果需要从容器连接主机,则必须简化隔离级别。您可以通过将网络模式更改为“主机”来完成此操作。

在docker撰写中你可以这样做:

network_mode:“host”(doc

© www.soinside.com 2019 - 2024. All rights reserved.