Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

Failed to connect to mongodb when using `docker-compose up`

Open mhkeller opened this issue 11 years ago • 16 comments

There could be a step I'm missing in the configuration but when I run docker-compose up. I get the following error. The first time I ran it, it failed. I ran it a second time and the error is thrown but the server launches. It seems none of the messages are saved to the database, tho, which would make sense given the errror.

rocketchat_1 | => Starting meteor app on port:80
rocketchat_1 | 
rocketchat_1 | /built_app/programs/server/node_modules/fibers/future.js:278
rocketchat_1 |                      throw(ex);
rocketchat_1 |                            ^
rocketchat_1 | Error: failed to connect to [mongodb:27017]
rocketchat_1 |     at Object.Future.wait (/built_app/programs/server/node_modules/fibers/future.js:398:15)
rocketchat_1 |     at new MongoConnection (packages/mongo/mongo_driver.js:213:1)
rocketchat_1 |     at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:1)
rocketchat_1 |     at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:1)
rocketchat_1 |     at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750:1)
rocketchat_1 |     at new Mongo.Collection (packages/mongo/collection.js:98:1)
rocketchat_1 |     at packages/accounts-base/accounts_common.js:141:1
rocketchat_1 |     at /built_app/programs/server/packages/accounts-base.js:243:4
rocketchat_1 |     at /built_app/programs/server/packages/accounts-base.js:1659:3
rocketchat_1 |     at /built_app/programs/server/boot.js:222:10
rocketchat_1 |     - - - - -
rocketchat_1 |     at [object Object].<anonymous> (/built_app/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/server.js:555:74)
rocketchat_1 |     at [object Object].emit (events.js:106:17)
rocketchat_1 |     at [object Object].<anonymous> (/built_app/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:156:15)
rocketchat_1 |     at [object Object].emit (events.js:98:17)
rocketchat_1 |     at Socket.<anonymous> (/built_app/programs/server/npm/mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
rocketchat_1 |     at Socket.emit (events.js:95:17)
rocketchat_1 |     at net.js:441:14
rocketchat_1 |     at process._tickCallback (node.js:448:13)

mhkeller avatar Oct 02 '15 15:10 mhkeller

if you do docker-compose ps what do you have running?

geekgonecrazy avatar Oct 02 '15 16:10 geekgonecrazy

I get the following. I have to ctrl-C the docker-compose up process to get type access to the console. Or do you want me to open up another docker shell and run docker-compose ps which the up process is running?

bash-3.2$ docker-compose ps
         Name                        Command                State     Ports 
---------------------------------------------------------------------------
rocketchat_mongodb_1      /entrypoint.sh mongod            Exit 0           
rocketchat_rocketchat_1   /bin/sh -c bash $METEORD_D ...   Exit 137  

mhkeller avatar Oct 02 '15 16:10 mhkeller

Running docker-compose ps in a new docker shell with the app running gives me

bash-3.2$ docker-compose ps
      Name               Command              State               Ports       
-----------------------------------------------------------------------------
rocketchat_mongod   /entrypoint.sh      Up                  0.0.0.0:32773->27 
b_1                 mongod                                  017/tcp           
rocketchat_rocket   /bin/sh -c bash     Up                  0.0.0.0:80->80/tc 
chat_1              $METEORD_D ...                          p                

mhkeller avatar Oct 02 '15 16:10 mhkeller

How does your docker-compose.yaml look? Have you made any changes?

marceloschmidt avatar Oct 02 '15 16:10 marceloschmidt

When you type docker-compose up make sure to specify the -d flag to daemonize it.

Like: docker-compose up -d

Otherwise any key stroke could bring mongo or rocket.chat down. Looks like in this case mongo isn't started. But if you did make any changes to your yml file that'd possibly effect it too.

geekgonecrazy avatar Oct 02 '15 16:10 geekgonecrazy

Only the ROOT_URL.

rocketchat:
  image: rocketchat/rocket.chat
  environment:
    - MONGO_URL=mongodb://mongodb/rocketchat
    - ROOT_URL=http://<our-ip-address>:8080
  links:
    - mongodb
  ports:
    - 80:80

mongodb:
   image: mongo
   ports:
     - 27017

Could it be something with the port? I'm running it off of 8080 per the issue in https://github.com/RocketChat/Rocket.Chat/issues/676#issuecomment-137788217

mhkeller avatar Oct 02 '15 16:10 mhkeller

I think your port is probably fine. Seems more and issue of mongo not being properly linked.

I'd make sure every thing is completely shutdown.

docker-compose stop docker-compose rm

Then try with docker-compose up -d

Be on the look out for errors with it coming up.

geekgonecrazy avatar Oct 02 '15 16:10 geekgonecrazy

When running it with -d where do I see the output that was previously in the terminal so I can look for errors?

mhkeller avatar Oct 02 '15 16:10 mhkeller

docker-compose logs

geekgonecrazy avatar Oct 02 '15 16:10 geekgonecrazy

okay i don't see the mongo error but now it says user not found when I try to log in

mhkeller avatar Oct 02 '15 16:10 mhkeller

Should be able to just register your user and be good to go.

Also if you need a little more real time assistance. Feel free to hit us up on our community chat in #support

geekgonecrazy avatar Oct 02 '15 16:10 geekgonecrazy

Doing rm and restarting seems to have solved this issue

mhkeller avatar Oct 02 '15 16:10 mhkeller

It work fine for me too. thankyou

nontachaiwebdev avatar Nov 24 '17 17:11 nontachaiwebdev

I was using the mongo-express image from docker hub and came here looking for a solution.

For me I gave the name of my mongo container a custom name and needed to tell the mongo-express container what it was because it defauls to 'mongo':

Name                            | Default         | Description
--------------------------------|-----------------|------------
ME_CONFIG_MONGODB_SERVER        | 'mongo'         | MongoDB container name. Use comma delimited list of host names for replica sets.

So in my docker-compose.yml I had to set the environment variable to match...

  mongo-express:
    image: mongo-express
    
    restart: always
    
    ports:
      - '8081:8081'
      
    links:
      - database    #link this service to the database service
      
    depends_on:
      - database
      
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example123
      ME_CONFIG_MONGODB_SERVER: database

Hope this saves someone some time...

adamja avatar Jun 16 '19 07:06 adamja

I was using the mongo-express image from docker hub and came here looking for a solution.

For me I gave the name of my mongo container a custom name and needed to tell the mongo-express container what it was because it defauls to 'mongo':

Name                            | Default         | Description
--------------------------------|-----------------|------------
ME_CONFIG_MONGODB_SERVER        | 'mongo'         | MongoDB container name. Use comma delimited list of host names for replica sets.

So in my docker-compose.yml I had to set the environment variable to match...

  mongo-express:
    image: mongo-express
    
    restart: always
    
    ports:
      - '8081:8081'
      
    links:
      - database    #link this service to the database service
      
    depends_on:
      - database
      
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example123
      ME_CONFIG_MONGODB_SERVER: database

Hope this saves someone some time...

THIS! thanks!

Untiring avatar Jul 25 '19 09:07 Untiring

Its issue with firewall. Follow these instructions to fix the issue https://stackoverflow.com/questions/40214617/docker-no-route-to-host

cleankoding-pradeep avatar Nov 24 '20 13:11 cleankoding-pradeep