簡體   English   中英

從 Docker 容器內部如何連接到 WSL2 分發

[英]From inside of a Docker container how to connect to a WSL2 distribution

設置

  • Docker 主機在 Windows 上使用 WSL 2 引擎
  • Linux (Ubuntu-20.04) WSL 2 分發與 WSL 2 集成
  • Docker 容器 ( webdevops/php-apache-dev ) 從 Ubuntu 開始
  • 容器端口映射 8000:8000

The PHP Web Application in the docker container is now reachable from Windows host via http://localhost:8000

在 Windows 和 php-apache-dev 容器中的 Xdebug 設置上運行 PhpStorm:

xdebug.remote_connect_back = 0
xdebug.remote_host = host.docker.internal

Xdebug 在 9000 端口連接到 PhpStorm,調試很好。

xdebug 日志:

I: Connecting to configured address/port: host.docker.internal:9000.
I: Connected to client. :-)
...

如果我在 Ubuntu 上運行 PhpStorm,Xdebug 無法訪問 PhpStorm。

Xdebug 日志:

I: Connecting to configured address/port: host.docker.internal:9000.
E: Time-out connecting to client (Waited: 200 ms). :-(

如何從我的 WSL2 Ubuntu 開始在 PhpStorm 中調試 php 應用程序?

原因是性能。 Ubuntu 中的 PhpStorm 文件索引比通過\\wsl$\Ubuntu-20.04的 Windows 快得多

我現在的解決方案是一種解決方法:

  • Ubuntu 中的 PHPStorm 監聽 9099 端口,
  • docker 容器中的 xdebug 使用xdebug.remote_host = host.docker.internal
  • Start a ssh tunnel from Windows to Ubuntu with port forwarding 9000.9099: ssh -R 9000:localhost:9099 localhost

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM