Search code examples
mongodbdockerauthenticationbitnami

Can authenticate to docker mongo instance with CLI, but not by any other means


I have a bitnami mongo image that i start using:

docker run -p 27017:27017 -it --name mongodb <myregistry>.azurecr.io/movo.mongodb

I seed the mongo database using a script from which the output can be seen on the left hand of the image.

The problem: I can connect the database using the mongo-cli. However, i can't authenticate using Robo3T or my C# solution, using an identical connectionstring..

This works:

docker exec -it mongodb  mongo admin -u movoproto -p "...<MyPwd>..."

But i cannot authenticate in any other way. The connection does not seem to be the problem...

I've got an identical setup on my laptop where it workes fine...

Problem illustration


Solution

  • After some fiddling i figured out what the issue was in the end.

    It appears mongodb on windows can start as a local service, which runs a database on 127.0.0.1:27017.

    So using Robo3T I was connecting to this local instance instead of my mapped docker mongo instance. With Robo3T i could connect to this local instance when i unticked 'Perform Authentication'.

    In Robo3T you can choose -> Right-click 'Open shell' -> db.hostInfo() -> F5 -> View results in text mode. This would give info about my desktop computer

    Whereas docker exec -it mongodb mongo --eval 'db.hostInfo()' would display information regarding my docker image.

    My solution was to disable the mongo service on my desktop pc that runs the local database.

    Doing this would let docker run -p 27017:27017 -it --name mongodb <myregistry>.azurecr.io/movo.mongodb bind to my docker container at 127.0.0.1:27017