Connecting to XDEBUG on remote Docker Image

386 Views Asked by At

I am trying to debug using NetBeans 11 as my client, Xdebug 3 on the Docker image. The Docker container is on a remote host. I am unable to make a connection. Indicator at the bottom of the NetBeans screen scrolls forever with "waiting for connection (netbeans-xdebug)". I am not sure what I am doing wrong. I have had this work in the past without Docker and with Xdebug 2, I am not sure if I messed up the Xdebug 3, the Docker or both.

My configurations:

Dockerfile adds Xdebug properly and I can see it in my container.

docker-compose.yml

---

services:
  drupal:
    container_name: intranet-finkenb2
    ports:
      - "8082:80"
      - "9092:9003"
    volumes:
      - /home/finkenb2/intranet/custom_themes:/opt/drupal/web/themes/custom
      - /home/finkenb2/intranet/custom_modules:/opt/drupal/web/modules/custom
    environment:
      XDEBUG_MODE: debug,develop
      XDEBUG_SESSION: netbeans-xdebug
      XDEBUG_CONFIG: >
        client_host = localhost
        client_port = 9003
        discover_client_host=true
        start_with_request=yes
  db:
    container_name: intranet-finkenb2-db
  solr:
    container_name: intranet-finkenb2-solr
    ports:
      - "8982:8983"

volumes:
  public_files:
  private_files:
  site_settings:

SSH Tunnel via PuTTY: R9092 localhost:9092

NetBeans PHP Debug config:

 - Debugger Port: 9092
 - Session ID: netbeans-xdebug
 - Maximum Data Length: 8192
 - Check: Stop at first line

NetBeans Project config (run configuration):

 - Run As: Remote Web Site
 - Project URL: http://intranet-finkenb2.devel.lib.msu.edu
 - index file: index.php
 - remote connection
   - hostname intranet8.devel.lib.msu.edu /*docker host server*/
   - user/pwd correct
   - initial directory /var/www/
1

There are 1 best solutions below

0
On

This is not correct:

ports
- "9092:9003"

Xdebug connects to your IDE, so you don't need to expose the port. These ports are for external exposures anyway, and you're SSH-ing into the container with -R already, so this makes no sense.

This is not correct:

  XDEBUG_CONFIG: >
    client_host = localhost
    client_port = 9003
    discover_client_host=true
    start_with_request=yes
  1. You can't use all of these as part of the XDEBUG_CONFIG variable, start_with_request, for example.
  2. discover_client_host with Docker doesn't work, as it gets the wrong IP through the gateway
  3. localhost is normally also not correct, as it needs to be the IP/hostname of the machine where your IDE listens. But you're SSH-ing into that container, so that should fine fine.
  4. With that SSH tunnel, you need to set client_port to the port of your remote SSH end point (9092).

If anything else is unclear, make a log file, or try to debug a page with xdebug_info() in it, and it will tell you what Xdebug has tried.