16
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Docker v18.03以降でコンテナからホストに接続したい(Docker for Windows)

Last updated at Posted at 2018-10-09

これを使う

host.docker.internalを使う。

使い方具体例

PHP+ApacheをDockerで建てて、ホストのエディタ兼デバッガにデバッグ情報を送信するときの設定。

php.ini
; Enable xdebug extension module
zend_extension=xdebug.so

xdebug.remote_enable=true
xdebug.remote_autostart=1
;xdebug.remote_connect_back=1
xdebug.remote_host=host.docker.internal  <-- これ
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.profiler_enable=0
xdebug.profiler_output_dir="/var/log/php_prof"

参考文献

公式文書

以下から抜粋。
https://docs.docker.com/docker-for-windows/networking/#use-cases-and-workarounds

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST
The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host. This is for development purpose and will not work in a production environment outside of Docker for Windows.

Google翻訳

コンテナからホスト上のサービスに接続したい
ホストにはIPアドレスが変更されています(ネットワークにアクセスできない場合はありません)。18.03以降host.docker.internal、ホストが使用する内部IPアドレスに解決される特別なDNS名に接続することをお勧め します。これは開発目的のためであり、Docker for Windows以外の運用環境では動作しません。

16
7
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
16
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?