{"action":"created","issue":{"url":"https://api.github.com/repos/showwin/QIDB/issues/121","repository_url":"https://api.github.com/repos/showwin/QIDB","labels_url":"https://api.github.com/repos/showwin/QIDB/issues/121/labels{/name}","comments_url":"https://api.github.com/repos/showwin/QIDB/issues/121/comments","events_url":"https://api.github.com/repos/showwin/QIDB/issues/121/events","html_url":"https://github.com/showwin/QIDB/issues/121","id":133595897,"number":121,"title":"Docker 環境で MongoDB のパスが解決できない","user":{"login":"showwin","id":1732016,"avatar_url":"https://avatars.githubusercontent.com/u/1732016?v=3","gravatar_id":"","url":"https://api.github.com/users/showwin","html_url":"https://github.com/showwin","followers_url":"https://api.github.com/users/showwin/followers","following_url":"https://api.github.com/users/showwin/following{/other_user}","gists_url":"https://api.github.com/users/showwin/gists{/gist_id}","starred_url":"https://api.github.com/users/showwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/showwin/subscriptions","organizations_url":"https://api.github.com/users/showwin/orgs","repos_url":"https://api.github.com/users/showwin/repos","events_url":"https://api.github.com/users/showwin/events{/privacy}","received_events_url":"https://api.github.com/users/showwin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"showwin","id":1732016,"avatar_url":"https://avatars.githubusercontent.com/u/1732016?v=3","gravatar_id":"","url":"https://api.github.com/users/showwin","html_url":"https://github.com/showwin","followers_url":"https://api.github.com/users/showwin/followers","following_url":"https://api.github.com/users/showwin/following{/other_user}","gists_url":"https://api.github.com/users/showwin/gists{/gist_id}","starred_url":"https://api.github.com/users/showwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/showwin/subscriptions","organizations_url":"https://api.github.com/users/showwin/orgs","repos_url":"https://api.github.com/users/showwin/repos","events_url":"https://api.github.com/users/showwin/events{/privacy}","received_events_url":"https://api.github.com/users/showwin/received_events","type":"User","site_admin":false},"milestone":null,"comments":1,"created_at":"2016-02-15T00:13:10Z","updated_at":"2016-02-15T00:29:34Z","closed_at":null,"body":"<img width=\"576\" alt=\"qidb\" src=\"https://cloud.githubusercontent.com/assets/1732016/13037443/20570bd0-d3c4-11e5-847c-4c0641171fb3.png\">\r\n<img width=\"576\" alt=\"qidb\" src=\"https://cloud.githubusercontent.com/assets/1732016/13037444/23568b58-d3c4-11e5-9068-68fee9e0c4ea.png\">\r\n"},"comment":{"url":"https://api.github.com/repos/showwin/QIDB/issues/comments/184011667","html_url":"https://github.com/showwin/QIDB/issues/121#issuecomment-184011667","issue_url":"https://api.github.com/repos/showwin/QIDB/issues/121","id":184011667,"user":{"login":"showwin","id":1732016,"avatar_url":"https://avatars.githubusercontent.com/u/1732016?v=3","gravatar_id":"","url":"https://api.github.com/users/showwin","html_url":"https://github.com/showwin","followers_url":"https://api.github.com/users/showwin/followers","following_url":"https://api.github.com/users/showwin/following{/other_user}","gists_url":"https://api.github.com/users/showwin/gists{/gist_id}","starred_url":"https://api.github.com/users/showwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/showwin/subscriptions","organizations_url":"https://api.github.com/users/showwin/orgs","repos_url":"https://api.github.com/users/showwin/repos","events_url":"https://api.github.com/users/showwin/events{/privacy}","received_events_url":"https://api.github.com/users/showwin/received_events","type":"User","site_admin":false},"created_at":"2016-02-15T00:29:34Z","updated_at":"2016-02-15T00:29:34Z","body":"@tomiit \r\nDocker 側のログを見ると `Could not resolve IP for: db:27017` と出ていて、MongoDB に接続できていないことがわかります。\r\n\r\n### MongoDB のパス解決の流れ\r\n`docker-compose.yml` で以下のように設定をしており、\r\n```yaml:docker-compose.yml\r\nqidb:\r\n  build: ./\r\n  command: '/app/docker/rails/start-server.sh'\r\n  volumes:\r\n    - ./:/app\r\n  ports:\r\n    - \"3000:3000\"\r\n  links:\r\n    - mongo:db              # 2. mongo を db という名前で扱えるようにする\r\n  environment:\r\n    - MONGODB_HOST=db      # 3. 環境変数 MONGODB_HOST の値を db にする\r\n  volumes_from:\r\n    - bundle\r\nmongo:                     # 1.  MongoDB を mongo という名前で登録\r\n  build: ./docker/mongo\r\n```\r\n\r\n`config/mongoid.yml` で\r\n```\r\ndevelopment:\r\n  sessions:\r\n    default:\r\n      database: qidb_development\r\n      hosts:\r\n        - <%= (ENV[\"MONGODB_HOST\"] || 'localhost') + ':27017' %>  # 環境変数 MONGODB_HOST が存在する場合には、そちらの値を使用する\r\n```\r\nとなっており、MongoDB へのパスが解決される流れになっています。\r\nが、今回はこちらに問題があるわけではありませんでした。\r\n\r\n### 今回の原因と解決方法\r\nFirefox でアクセスしているURLを見ると、`0.0.0.0:3000` にアクセスしているようですね。\r\nこれはおそらく Docker 上で立ち上がっているものではなくて、Windows 環境で `rails server` をして立ち上がっているサーバにアクセスしているのではないかと思います。 WIndows 環境には MongoDB は立ち上げていないので、MongoDB にアクセスできません、とエラーが出ているのだと思います。\r\n\r\n#103 の書き方がわかりにくかったかもしれませんが、Docker が起動しているIPアドレスを確認してください。\r\n```\r\n$ docker-machine ls                                                                                                                                       t111@QIDB\r\nNAME      ACTIVE   DRIVER       STATE     URL                         SWARM   ERRORS\r\ndev   *        virtualbox   Running   tcp://192.168.99.100:2376\r\n```\r\nのように出てくると思いますので、この場合は `192.168.99.100` が Docker が動いている仮想マシンのIPアドレスです。\r\n\r\n```\r\n$ docker-compose ps                                                                                                                                       t111@QIDB\r\n    Name                   Command               State            Ports\r\n--------------------------------------------------------------------------------\r\nqidb_bundle_1   /bin/sh                          Exit 0\r\nqidb_mongo_1    /entrypoint.sh mongod            Up       27017/tcp\r\nqidb_qidb_1     /app/docker/rails/start-se ...   Up       0.0.0.0:3000->3000/tcp\r\n```\r\nとすると、QIDB のアプリケーション `qidb_qidb_1` が( **仮想マシンの**ローカルホスト `0.0.0.0` の)3000番ポートで動いているのがわかりますので、`192.168.99.100:3000` にアクセスすると、Docker上で動いている QIDB にアクセスすることができます。"}}