Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to connect to mongodb when using docker-compose up #962

Closed
mhkeller opened this issue Oct 2, 2015 · 16 comments
Closed

Failed to connect to mongodb when using docker-compose up #962

mhkeller opened this issue Oct 2, 2015 · 16 comments

Comments

@mhkeller
Copy link

mhkeller commented Oct 2, 2015

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)
@geekgonecrazy
Copy link
Contributor

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

@mhkeller
Copy link
Author

mhkeller commented Oct 2, 2015

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
Copy link
Author

mhkeller commented Oct 2, 2015

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                

@marceloschmidt
Copy link
Member

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

@geekgonecrazy
Copy link
Contributor

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.

@mhkeller
Copy link
Author

mhkeller commented Oct 2, 2015

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 #676 (comment)

@geekgonecrazy
Copy link
Contributor

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.

@mhkeller
Copy link
Author

mhkeller commented Oct 2, 2015

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

@geekgonecrazy
Copy link
Contributor

docker-compose logs

@mhkeller
Copy link
Author

mhkeller commented Oct 2, 2015

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

@geekgonecrazy
Copy link
Contributor

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

@mhkeller
Copy link
Author

mhkeller commented Oct 2, 2015

Doing rm and restarting seems to have solved this issue

@mhkeller mhkeller closed this as completed Oct 2, 2015
@nontachaiwebdev
Copy link

It work fine for me too. thankyou

@adamja
Copy link

adamja commented Jun 16, 2019

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

@Untiring
Copy link

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!

@cleankoding-pradeep
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants