I am creating a docker container for a mongod server following the suggestions made here. My docker compose file looks as follows:
version: '3.2'
services:
mongo:
container_name: mongo
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
volumes:
- ./data:/data/db
ports:
- "27017:27017"
I then build and run the container using the docker compose command:
docker-compose up --build
In the start up logs I can see the user being created:
mongo | 2018-12-03T04:40:00.562+0000 I STORAGE [conn2] createCollection:
admin.system.users with generated UUID: ...
mongo | Successfully added user: {
mongo | "user" : "admin",
mongo | "roles" : [
mongo | {
mongo | "role" : "root",
mongo | "db" : "admin"
mongo | }
mongo | ]
mongo | }
When I try to start mongo using the auth for that user, I get an authorization error though:
mongo -u "admin" -p "admin"
2018-12-03T04:47:34.752+0000 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1608:20
@(auth):6:1
@(auth):1:2
exception: login failed
What's the correct command to connect to mongo using the above credentials?