Skip to content

Instantly share code, notes, and snippets.

@valorad
Forked from wcxaaa/docker_mongo_Init.md
Last active October 23, 2020 21:44
Show Gist options
  • Save valorad/40bd4dad5fc94adf03f3451868634213 to your computer and use it in GitHub Desktop.
Save valorad/40bd4dad5fc94adf03f3451868634213 to your computer and use it in GitHub Desktop.
Dockerized mongoDB initialization

First, create a mongod config file. e.g.

# Where and how to store data.
storage:
  dbPath: /data/db
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
  authorization: enabled
  

Then run mongo.

docker run --name mongo-c1 -d \
--network my-vps-main-network \
-e MONGO_INITDB_ROOT_USERNAME=[mongoAdminName e.g. root] \
-e MONGO_INITDB_ROOT_PASSWORD=[some-initial-password] \
-v /workspace/www/mongo/mongod.conf:/etc/mongod.conf \
-v /workspace/www/mongo/data:/data/db \
-v /workspace/downloadCenter:/workspace/downloadCenter \
mongo -f /etc/mongod.conf

In future, to login to mongo, type:

docker exec -it mongo-c1 mongo -u root -p 'some-initial-password' --authenticationDatabase admin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment