A
A
Alexander Pankov2022-03-06 22:38:48
PHP
Alexander Pankov, 2022-03-06 22:38:48

Where is the problem when setting up xdebug on a remote docker machine?

Hello
, there is a test project (one index.php file)
rises in the docker on vps (ubuntu) (remote server)
here is the compose config

version: '3.1'

services:
  webserver:
    build:
      context: docker
      dockerfile: nginx/Dockerfile
    working_dir: /application
    volumes:
      - './:/application'
    ports:
      - '180:80'

  php-fpm:
    build:
      context: docker
      dockerfile: php-fpm/Dockerfile
    working_dir: /application
    volumes:
      - './:/application'
    environment:
      PHP_IDE_CONFIG: "serverName=example"
networks:
  default:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.18.0.0/16

everything rises, is available and php is working out the
docker inspect of the c php container shows
"Gateway" : "172.18.0.1",
        "IPAddress" : "172.18.0.2",

as indicated in the compose file
So, now the task is to debug (on the phpstorm laptop) this application, respectively, xdebug (v3) is installed in the container phpinfo sees
it here is its config
xdebug.idekey=PHPSTORM
xdebug.mode=debug
xdebug.client_host=172.18.0.1
xdebug.remote_port=9003

We now have a docker container with php installed and xdebug
we can reach it through the browser, the project files are on the laptop (they are thrown into the docker (volume) via rsync)
I work in phpstorm there I set up the necessary tabs, everything works (validation passes)

The situation is such
that when request from the browser (with the XDEBUG cookie set)
xdebug itself initializes the connection to 9003 (from its settings) this connection is forwarded to the machine where the docker is running (Ubuntu)
I need to create a tunnel so that everything that came on the 9003 port of Ubuntu was broadcast to my laptop, to which phpStorm (pipe) listens to it, but for some reason it doesn’t work out for me ...
how do I do
1) I raise the docker
2) I forward the port ssh -R 9003: localhost: 9003 [email protected]
3) I set a breakpoint, "pick up the phone" in phpstrom
4) I refresh the browser page and nothing

itself xdebug writes this
Creating socket for '172.18.0.1:9003', poll success, but error: Operation in progress (29).
Could not connect to debugging client. Tried: 172.18.0.1:9003 (through xdebug.client_host/xdebug.client_port) :-(


a laptop
❯ netstat -nat | grep 9003 | grep LISTEN
tcp46      0      0  *.9003                 *.*                    LISTEN


ubuntu
~/projects/simple$ netstat -an | grep 9003
tcp        0      0 127.0.0.1:9003          0.0.0.0:*               LISTEN


I can’t understand what I’m doing wrong, I
found such a question, it seems the same problem: https://qna.habr.com/q/392317
but the solution written there is not clear to me (I don’t understand networks well, devops terms )
tell me everything is the same or not, or am I doing everything wrong and how do I need it?
the task is to debug an application through xdebug that is in a container that is running on a remote machine

Without much understanding of what I'm doing, but I did it
on ubuntu
ssh -g -L 9003:localhost:9000 -f -N 127.0.0.1
on a laptop with phpstorm (configured port 9000 for xdebug)
ssh -R 9000:localhost:9000 vps -v
turn on the pipe, breakpoint and browser extension, update page
in the terminal on every page refresh is
debug1: client_input_channel_open: ctype forwarded-tcpip rchan 2 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 9000, originator 127.0.0.1 port 59934
debug1: connect_next: host localhost ([127.0.0.1]:9000) in progress, fd=9
debug1: channel 1: new [127.0.0.1]
debug1: confirm forwarded-tcpip
debug1: channel 1: connection failed: Connection refused
setsockopt TCP_NODELAY: Invalid argument
debug1: connect_next: host localhost ([::1]:9000) in progress, fd=10
debug1: channel 1: connection failed: Connection refused
connect_to localhost port 9000: failed.
debug1: channel 1: free: 127.0.0.1, nchannels 2
debug1: client_input_channel_open: ctype forwarded-tcpip rchan 2 win 2097152 max 32768
debug1: client_request_forwarded_tcpip: listen localhost port 9000, originator 127.0.0.1 port 59940
setsockopt TCP_NODELAY: Invalid argument
debug1: connect_next: host localhost ([127.0.0.1]:9000) in progress, fd=9
debug1: channel 1: new [127.0.0.1]
debug1: confirm forwarded-tcpip
debug1: channel 1: connection failed: Connection refused
setsockopt TCP_NODELAY: Invalid argument
debug1: connect_next: host localhost ([::1]:9000) in progress, fd=10
debug1: channel 1: connection failed: Connection refused
connect_to localhost port 9000: failed.
debug1: channel 1: free: 127.0.0.1, nchannels 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pankov, 2022-03-06
@PankovAlxndr

I looked here when I did
https://onedev.net/post/326
there is also a topic with host.docker.internal (I have docker 20.10+) it should work, but I didn’t understand how it was and what,
I couldn’t find dns from inside the containers comparisons nowhere, what and how it should work and "crawl" to the host machine with docker - I did not understand

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question