yukofebの日記

個人的な技術メモ。

dockerコンテナのnginxでConnection refused

dockerコンテナでnginxを動作させてみる。
nginxを起動してcurlでアクセスしてみたものの、Connextion refusedと出力されてしまう。

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
50802d9a477a        yukofeb/nginx       "/usr/sbin/nginx -g '"   17 minutes ago      Up 8 minutes        0.0.0.0:80->80/tcp   nginx1

$ curl localhost:80
curl: (7) Failed to connect to localhost port 80: Connection refused

ドキュメントによるとDOCKER_HOST0.0.0.0に設定されていないことが原因らしい。
Installation on Mac OS X

DOCKER_HOSTのIPを確認する方法は以下。

$ docker-machine ip default
192.168.99.100

これでOK!

$ curl 192.168.99.100:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>