Search code examples
phpdockerphpstormxdebugssh-tunnel

PhpStorm + Docker + Xdebug + DB SSH tunnel


Locally I have following docker-compose configuration:

nginx:
  build:
    context: ./nginx
  ports:
    - "80:80"
  volumes:
    - ./../logs:/home/web/logs/
    - ./../:/home/web/my-website.com/
  depends_on:
    - php
php:
  build:
    context: ./php
  volumes:
    - ./../:/home/web/my-website.com/
  working_dir: /home/web/my-website.com/
  expose:
    - "8123"

php container has Xdebug installed into it, I can easily connect to it from PhpStorm.

I have remote ClickHouse database which is connected via SSH Tunnel. When I start my container I just go into my container and execute:

ssh -4 [email protected] -p 2211 -L 8123:localhost:8123 -oStrictHostKeyChecking=no -Nf

After this, my site is able to use this connection, but when I execute console command

./yii analysis/start-charts 003b56fe-db47-11e8-bcc0-52540010e5bc 205

from PhpStorm, I'm getting an exception:

Failed to connect to 127.0.0.1 port 8123: Connection refused

If I jump into the container and launch the same command, everything works fine.

What's wrong? Why PhpStorm doesn't see my SSH tunnel?


Solution

  • I've got an answer on "superuser" site: https://superuser.com/questions/1374463/phpstorm-docker-xdebug-db-ssh-tunnel/1375961#1375961

    Besides, I've added ports node to my php container definition, now it's the following:

      php:
        build:
          context: ./php
        volumes:
          - ./../:/home/web/my-website.com/
        working_dir: /home/web/my-website.com/
        expose:
          - "8123"
        ports:
          - "8123:8123"
        depends_on:
          - redis
          - mysql