Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Last active September 16, 2021 03:01
Show Gist options
  • Save aaronksaunders/06b1808e95440e32ed74e7d38161a86d to your computer and use it in GitHub Desktop.
Save aaronksaunders/06b1808e95440e32ed74e7d38161a86d to your computer and use it in GitHub Desktop.
Docker With Mongo

Docker With Mongo

My helper for creating a docker container running mongo where i set the super and then create a user. I also want the data to persist so i have added a volume

version: '3'
services:
mongodb:
image: mongo:4.2
environment:
MONGO_INITDB_ROOT_USERNAME: aks_root
MONGO_INITDB_ROOT_PASSWORD: aks_root
ports:
- '27017:27017'
volumes:
- db_data:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
volumes:
db_data:
conn = new Mongo();
db = conn.getDB("test-database");
db.createUser(
{
user: "test-user",
pwd: "test-password",
roles: [
{
role: "dbOwner",
db: "test-database"
}
]
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment