LoginSignup
1
0

Docker内GuzzleでCould not resolve hostになる場合の対処

Posted at

Docker内のサーバーPHP処理で、Guzzleで共有サーバーに接続しようとすると、エラーになった。

error
GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: remote.address (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for ...

どうやらDocker内から通信しようとしているので、Windowsの/etc/hostsは見てないらしい。

Dockerコンテナ内の/etc/hostsに自動的に書き込むには、composeを使っているなら、docker-compose.ymlのphpコンテナの記載に追記する。

docker-compose.yml
php:
    #.....
    
    extra_hosts:
      - "${remote_address}:${actual_ip}"

composeを使っていない場合は以下の記事が参考になる。

参考

1
0
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
1
0