I tried to build a mongo db manually, here is the code to start the container
sudo docker run -d --name mongodb1 -p 27017:27017 -v mongo_db:/data/db1 \
-e MONGO_INITDB_DATABASE=admin \
-e MONGO_INITDB_ROOT_USERNAME=mongoadmin \
-e MONGO_INITDB_ROOT_PASSWORD=secret mongo:latest
The container was created successfully, but there is no any default database such as admin. When I tried to create a collection, I got below error message. I checked the existing thread How to enable authentication on MongoDB through Docker?, but it did not help for my case.
> show dbs
> use customer
switched to db customer
> db.createCollection("customerList")
{
"ok" : 0,
"errmsg" : "command create requires authentication",
"code" : 13,
"codeName" : "Unauthorized"
}