LoginSignup
2
2

More than 5 years have passed since last update.

Dockerのport forwardingでLinuxとOS Xでの違いにハマったという話

Posted at

TL;DR
Docker Machineのマニュアルを読めばOK。

普段はLinuxをホストにして使ってるのでdocker run時に-p 8080:80とかした場合、↓のように127.0.0.1を使えばコンテナ内の80ポートにアクセスできてたわけで、特に何も考えてなかったのです。

curl http://127.0.0.1:8080/

でも、OS Xの場合だとOS Xとコンテナゲストの間にVirtualBoxがいるんですよね。なので、Linuxのノリで127.0.0.1を使うとアクセスできない。

$ curl -I http://127.0.0.1:8080/
curl: (7) Failed to connect to 127.0.0.1 port 8080: Connection refused

そのため、IPアドレスを調べておいて、

$ docker-machine ip
192.168.99.100

そのIPアドレスでアクセスする必要がある。

masami@zen:~$ curl -I http://192.168.99.100:8080/
HTTP/1.1 200 OK
Server: nginx/1.9.14
Date: Wed, 27 Apr 2016 13:52:56 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 05 Apr 2016 15:20:43 GMT
Connection: keep-alive
ETag: "5703d7cb-264"
Accept-Ranges: bytes

192.168.99.100はVirtualBoxのVMでホストオンリーアダプタに設定されているアドレスです。
Linux環境ではdocker-machineを使っていないので、この場合、VMを挟むのかどうかってのは調べて無いですが。

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