LoginSignup
3
4

More than 5 years have passed since last update.

Docker環境からローカル環境にアクセスする方法

Last updated at Posted at 2018-06-12

WebアプリケーションはDocker(docker-compose)で構築しており、ローカル環境のAPIにアクセスしたい場合の方法です。

Docker for Macを利用している想定で説明をします。

例えばAPIをポート3001で立ち上げた場合、http://localhost:3001とDocker内で設定しているとうまく接続できません。

http://docker.for.mac.localhost:3001 と指定するとうまく接続できます。

docker.for.mac.localhost はDokcer for Macのver17.06から推奨されているDNSです。
ver18.03からはdocker.for.mac.localhost の代わりにhost.docker.internalを利用することが推奨されています。

なお、APIは127.0.0.1にbindすることでDockerからでも接続できるようになります。

参考
https://docs.docker.com/v17.09/docker-for-mac/networking
https://docs.docker.com/docker-for-mac/networking

by @nishina555

3
4
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
3
4