Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Unable to connect to mongoDB using fig #142

Closed
jonaswindey opened this issue Aug 17, 2014 · 3 comments
Closed

Unable to connect to mongoDB using fig #142

jonaswindey opened this issue Aug 17, 2014 · 3 comments

Comments

@jonaswindey
Copy link

When I try to launch the application locally with 'fig up', the application can't connect to mongoDB.

Howerver, 'docker ps' lists the containers and the ports (+ forwarding) are looking fine:

3fedba82aa1a        mean_web:latest     grunt                  2 hours ago         Up About a minute   35729/tcp, 0.0.0.0:3000->3000/tcp   mean_web_1                                       
8bf4847c2c5f        mongo:2.6           /usr/src/mongo/docke   2 hours ago         Up About a minute   0.0.0.0:27017->27017/tcp            mean_db_1,mean_web_1/db_1,mean_web_1/mean_db_1  

When starting fig:

db_1  | 2014-08-17T13:21:52.736+0000 [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=8bf4847c2c5f
db_1  | 2014-08-17T13:21:52.737+0000 [initandlisten] db version v2.6.1
db_1  | 2014-08-17T13:21:52.737+0000 [initandlisten] git version: f3327851aa89d923465a1b361f5d5a3d4139342c
db_1  | 2014-08-17T13:21:52.737+0000 [initandlisten] OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
db_1  | 2014-08-17T13:21:52.737+0000 [initandlisten] build info: Linux 7a5e40dd9807 3.8.0-23-generic #34-Ubuntu SMP Wed May 29 20:22:58 UTC 2013 x86_64 BOOST_LIB_VERSION=1_49
db_1  | 2014-08-17T13:21:52.737+0000 [initandlisten] allocator: tcmalloc
db_1  | 2014-08-17T13:21:52.737+0000 [initandlisten] options: {}
db_1  | 2014-08-17T13:21:52.738+0000 [initandlisten] journal dir=/data/db/journal
db_1  | 2014-08-17T13:21:52.738+0000 [initandlisten] recover : no journal files present, no recovery needed
db_1  | 2014-08-17T13:21:52.791+0000 [initandlisten] waiting for connections on port 27017

...

web_1 | MEAN.JS application started on port 3000
web_1 | [Error: failed to connect to [localhost:27017]]
web_1 |  Could not connect to MongoDB!

Anyone an idea? I'm new to fig/docker but I'm very interested to start using it. Thanks

@jonaswindey
Copy link
Author

Ok, I have found a possible explanation, I'm using boot2docker on OSx (https://github.com/boot2docker/boot2docker) which apparently uses NAT forwarding.

This means that I can't use 0.0.0.0 or localhost, but I have to use the ip that boot2docker provides

bash-3.2$ boot2docker ip

The VM's Host only interface IP address is: 192.168.59.103

So now I'll have to investigate how to forward this ip (which is probably dynamicly created) to fig or the mean project docker's mongodb ip

@gu-fan
Copy link

gu-fan commented Sep 5, 2014

I've got this problem too.

web_1 | MEAN.JS application started on port 3000
web_1 |  Could not connect to MongoDB!
web_1 | [Error: failed to connect to [localhost:27017]]
db_1  | 2014-09-05T09:27:16.007+0000 [clientcursormon] mem (MB) res:25 virt:340

docker ps

CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS                               NAMES
aed431d0896a        mt_web:latest       "grunt"                2 minutes ago       Up 2 minutes        35729/tcp, 0.0.0.0:3000->3000/tcp   mt_web_1    
cc8af8fdeeb7        mongo:2             "/entrypoint.sh mong   2 minutes ago       Up 2 minutes        0.0.0.0:27017->27017/tcp            mt_db_1,mt_

using lxc-docker, under ubuntu 14.04 64 VPS.
the VPS's ifconfig

docker0   Link encap:Ethernet  HWaddr 8e:13:77:b1:10:96
          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17713 errors:0 dropped:0 overruns:0 frame:0
          TX packets:20929 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1684167 (1.6 MB)  TX bytes:74501087 (74.5 MB)

eth0      Link encap:Ethernet  HWaddr 00:16:3e:00:25:a7
          inet addr:10.168.14.87  Bcast:10.168.15.255  Mask:255.255.248.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:72327 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3400 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3484731 (3.4 MB)  TX bytes:285652 (285.6 KB)

eth1      Link encap:Ethernet  HWaddr 00:16:3e:00:22:c6
          inet addr:121.40.134.173  Bcast:121.40.135.255  Mask:255.255.252.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4031196 errors:0 dropped:0 overruns:0 frame:0
          TX packets:97900 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1230615428 (1.2 GB)  TX bytes:8136949 (8.1 MB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:7069 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7069 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1659117 (1.6 MB)  TX bytes:1659117 (1.6 MB)

@mixmaster
Copy link

A slight change to the db configuration in config/env/development.js should make it work.

module.exports = {
    db: 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean-dev',
...

alex2006hw pushed a commit to alex-node/mean that referenced this issue Nov 21, 2014
brownman added a commit to linnovate/mean that referenced this issue Dec 17, 2014
this should allow running 1 container for the db and 1 for the web-app

as seen here:
meanjs/mean#142
loyaldev03 added a commit to loyaldev03/mean_stack_dev that referenced this issue Jan 8, 2018
this should allow running 1 container for the db and 1 for the web-app

as seen here:
meanjs/mean#142
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants