I am trying to create a custom container which also contains MongoDB (hence not using the official MongoDB container). I am trying to add authentication to the database, and I think I am having an issue in persisting authentication data, i.e. in dockerfile I run the following command at some point:
RUN (nohup mongod &) && mongo < /data/mongo.js
and mongo.js is:
use admin
db.createUser(
{
user: "admin",
pwd: "abcd",
roles: [ "root" ]
}
)
which yields below during build:
Successfully added user: { "user" : "admin", "roles" : [ "root" ] }
Removing intermediate container...
So after build, when I login to the container and start mongo with --auth flag, still can't login:
# mongo -u admin -p abcd --authenticationDatabase "admin"
MongoDB shell version: 3.2.11
Enter password:
connecting to: abcd
exception: login failed
What is missing?