Installation
docker run -d \ --name localMongoDb ❶\ -e MONGO_INITDB_ROOT_USERNAME=admin ❷\ -e MONGO_INITDB_ROOT_PASSWORD=secret ❷\ -e MONGO_INITDB_DATABASE=admin ❸\ -v ~/Data/Mongo:/data/db ❹\ -p 27017:27017 ❺\ mongo:4.4.1 ❻
Container name. |
|
The mongoDB instance administrator's name and password. |
|
Th administrative user's database. |
|
Mapping your host system's directory
|
|
Mapping MongoDB's standard port to your host system. |
|
Docker image mongo at version 4.4.1 |
docker-compose.yml |
mongo-init.js |
---|---|
|
|
|
> mongo -u admin -p secret admin
...
db.createUser(
... {
... user: "explorer",
... pwd: "secret",
... roles: [
... {
... role: "readWrite",
... db: "exploredb"
... }
... ],
... passwordDigestor: "server"
... }
... );
Successfully added user: { "user" : "explorer"...
> mongo -u explorer -p secret admin
...
> use exploredb
switched to db exploredb
> db.user.insert(
... { cname: "Eve Gardener",
... uid: "gardener",
... email: "gardener@betrayer.com"
... }
... )
WriteResult({ "nInserted" : 1 })
>
> db.user.find()
{ "_id" : ObjectId("5fa1c79d661a55242658f135"),
"cname" : "Eve Gardener", "uid" : "gardener", "email" : "gardener@betrayer.com" }