Unable to connect to mongodb running in docker on windows server 2019

I can connect to mongodb using compass, running in docker container on windows server 2019, when docker is run without auth.
But when I implement auth using the following command:

docker run -itd -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=user -e MONGO_INITDB_ROOT_PASSWORD=pass --name mymongo mongo:latest mongod --auth

I’m getting timeout error message when trying to connect using MongoDb compass.

Also when I try to connect directly using
docker exec -it mymongo powershell

then try to run
mongo
result in error message

mongo : The term ‘mongo’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • mongo
  •   + CategoryInfo          : ObjectNotFound: (mongo:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    

Can anyone guide me how to resolve this issue? I have followed many threads to resolve this issue with no luck so far.

I have tried many threads and guides but none of them worked for me.

Leave a Comment