Skip to content

Instantly share code, notes, and snippets.

@saliksyed
Created March 26, 2020 19:20
Show Gist options
  • Save saliksyed/a37679ff251fa0c8994a576de022095d to your computer and use it in GitHub Desktop.
Save saliksyed/a37679ff251fa0c8994a576de022095d to your computer and use it in GitHub Desktop.

3. Setup local MongoDB server as a Docker container

3.1. Download and launch local mongo docker image.

sudo docker run -p 27017:27017 --name some-mongo -d mongo --auth

This will download the official mongo Docker image and run it in detached mode with auth turned on.

3.2. Setup initial admin user in local MongoDB.

3.2.1 Launch a bash shell inside mongo container

sudo docker exec -it some-mongo bash

you should get a bash terminal inside the container, like

root@093275de44e7:/#

3.2.2 Run initial mongo shell

mongo admin

you should get a mongo shell like

(some message)
>

3.2.3 Create initial admin user

db.createUser({user: 'admin', pwd: 'password', roles:[{role: 'root', db: 'admin'}] })

The username and password can be changed here to your own choice.

After this you should see a message like

Successfully added user: {
	"user" : "admin",
	"roles" : [
		{
			"role" : "root",
			"db" : "admin"
		}
	]
}

3.3 Setup user for sirius

3.3.1 First exit the current mongo shell

> exit

3.3.2 Login back again with the just-created admin user

mongo -u admin -p password --authenticationDatabase admin

If successful, you should get a new mongo shell like

(some message)
>

3.3.3 Switch to a new database called testdb

> use testdb

3.3.4 Create the user sirius in testdb

db.createUser({user: 'sirius', pwd: 'valis', roles:[{role: 'readWrite', db: 'testdb'}, {role: 'readWrite', db:'database'}, {role: 'readWrite', db:'database1'}, {role: 'readWrite', db:'userdb'}, {role: 'readWrite', db:'analysisdb'}] })

After this step, you should see another Successfully added user message, and your MongoDB container is ready to go!

Note: Here the MongoDB does not have any data yet. We will first run SIRIUS in a docker image in the next step, then upload data in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment