LoginSignup
19
2

More than 3 years have passed since last update.

環境

Docker Desktop (Preview): 0.0.0(1)
OS: macOS Big Sur 11.1
IDE: PHPStorm

PHP: 7.2
Xdebug: 2.9.8

前提

通常のXdebug設定とかは割愛。
既存(Intel Macbook)で動いている環境が動かない、という状態。

現象

php.ini にて設定した xdebug.log に以下のようなエラーが。

[71] Log opened at 2020-12-29 07:57:31
[71] I: Connecting to configured address/port: host.docker.internal:9005.
[71] W: Creating socket for 'host.docker.internal:9000', getaddrinfo: Invalid argument.
[71] E: Could not connect to client. :-(
[71] Log closed at 2020-12-29 07:57:36

原因と解決

Docker公式ドキュメント既知の問題 として上がってた :sweat:

The DNS name host.docker.internal only works if you add --add-host=host.docker.internal:host-gateway to the docker run command

DNS名の host.docker.internal は docker run--add-host=host.docker.internal:host-gateway を追加しないと使えないとのこと。

これを docker-compose でやるなら、

    extra_hosts:
      - "host.docker.internal:host-gateway"

を書いてあげる必要がある。

そうすると、コンテナ内の /etc/hosts にて以下の記述を発見。

192.168.65.1    host.docker.internal

これで動く。。。とはならない。

E: Time-out connecting to client (Waited: 200 ms). :-(

接続がタイムアウトしてしまう模様。。。

どうやらコンテナ -> ホスト(Mac)の通信が届いていない感じ。

色々試した結果、 host-gateway を自分のIPにすると動いた!

    extra_hosts:
      - "host.docker.internal:192.168.xxx.xxx"

自分のIPはターミナル上にて以下で取れます。

ipconfig getifaddr en0

今後の課題

これで一応解決。。。ではあるけれど、普通はDHCPでIPとか自動設定されるし、IPを動的に変わるようにしたい。。。

IPを環境変数に詰めて、ビルドのときにそれを読み込むようにするか、コンテナ内のホストを書き換えるスクリプトを書くか。。。

19
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
2