I have been having quite a time connecting to a Dockerized instance of MongoDB. I was able to configure a MongoDB container per these instructions on my local development machine, but the same steps don't seem to work in production.

My exact steps to create, run and connect to the container:

  1. Create and run the container

    docker run --name prod-mongo -p 27017:27017 -d mongo --auth

  2. Added the initial user:

    docker exec -it prod-mongo mongo admin

    db.createUser({user:'skipper', pwd:'skipperspassword', roles:[{role:'userAdminAnyDatabase',db:'admin'}] });

  3. Successfully connected to Docker container from another Mongo container:

    docker run -it --rm --link prod-mongo:mongo mongo mongo -u skipper -p --authenticationDatabase admin prod-mongo/skippers-apps

  4. Unsuccessfully connected to Docker container from Docker host: mongo skippers-apps --authenticationDatabase admin -u skipper -p

It's that last step that I'm concerned with. It works in my local development environment, but not production.

Development Environment

  • Operating System: Mac OS El Capitan
  • Kernel Version 15.6.0
  • MongoDB Shell Version: 3.2.7
  • Docker Version: 1.12.3

Production Environment

  • Operating System: Ubuntu 16.04.1 LTS
  • Kernel Version: 4.4.0
  • MongoDB Shell Version: 2.6.10
  • Docker Version: 1.12.3

While I'm not sure why the version of MongoDB I was using previously (2.6.10) wasn't playing well with Docker, I was able to solve the problem by upgrading the version of the MongoDB client.

I would be curious to know the exact reason that a 2.6.10 client couldn't connect to the MongoDB server in the default Docker MongoDB image.

Solution: upgraded the MongoDB client from 2.6.10 to 3.2.11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.