Skip to content

Commit

Permalink
add mongo user and root password
Browse files Browse the repository at this point in the history
  • Loading branch information
finxol committed Jul 6, 2022
1 parent 665686b commit b3a521e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion docker-compose-mongo.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
version: '3'

services:
mongodb:
mongo:
image: mongo:5
restart: always
volumes:
- "./mongo-entrypoint.sh:/docker-entrypoint-initdb.d/1-init-db.sh:z"
env_file:
- '.mongo.env'
ports:
- "27017:27017"
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
restart: always
volumes:
- './mongodb:/data/db'
- "./mongo-entrypoint.sh:/docker-entrypoint-initdb.d/1-init-db.sh:z"
env_file:
- '.mongo.env'
networks:
Expand Down
4 changes: 4 additions & 0 deletions mongo-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo "Creating mongo users..."
mongo admin --host localhost -u "${MONGO_INITDB_ROOT_USERNAME}" -p "${MONGO_INITDB_ROOT_PASSWORD}" --eval "db.createUser({user: '${MONGO_USER}', pwd: '${MONGO_PASSWORD}', roles: [{role: 'readWrite', db: '${MONGO_INITDB_DATABASE}'}]});"
echo "Mongo users created."

0 comments on commit b3a521e

Please sign in to comment.