Step 4 : RUN mongod --fork --logpath /var/log/mongodb.log && sleep 5 && mongo foobar /tmp/create_ddbb.js
---> Running in 58ba44d02508
about to fork child process, waiting until server is ready for connections.
forked process: 9
child process started successfully, parent exiting
MongoDB shell version: 3.2.6
connecting to: foobar
Successfully added user: {
"user" : "***********",
"roles" : [
{
"role" : "readWrite",
"db" : "foobar"
}
]
}
---> e73b6c8c8b83
Removing intermediate container 58ba44d02508
Successfully built e73b6c8c8b83
so the user is created, but then when I try to connect, I get:
mongo_1 | 2016-05-13T17:44:02.159+0000 I NETWORK [initandlisten] connection accepted from 172.20.0.4:41294 #1 (1 connection now open)
mongo_1 | 2016-05-13T17:44:02.160+0000 I ACCESS [conn1] SCRAM-SHA-1 authentication failed for ********* on foobar from client 172.20.0.4 ; UserNotFound: Could not find user *********@foobar
mongo_1 | 2016-05-13T17:44:02.160+0000 I NETWORK [conn1] end connection 172.20.0.4:41294 (0 connections now open)
Why is that happening? How can I persist the created user?
the user should be added in the admin database so like this:
RUN mongod --fork --logpath /var/log/mongodb.log \
&& sleep 5 && mongo foobar /tmp/create_ddbb.js