Created
July 25, 2018 18:15
-
-
Save jonfriesen/ef57b8cfe80a608d649c0485e8665061 to your computer and use it in GitHub Desktop.
Shows how to create a docker mongo status checker and run command after it connects successfully
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.0' | |
services: | |
mongo: | |
image: mongo | |
ports: | |
- "27017:27017" | |
- "28017:28017" | |
environment: | |
MONGO_INITDB_ROOT_USERNAME: mongoadmin | |
MONGO_INITDB_ROOT_PASSWORD: secret | |
mongo-config: | |
image: mongo | |
depends_on: | |
- mongo | |
command: > | |
/bin/bash -c " | |
until mongo --host mongo -u mongoadmin -p secret --authenticationDatabase admin --eval \"printjson(db.serverStatus())\" | |
do | |
echo sleeping; | |
sleep 3; | |
done; | |
echo Successfully Connected, running Mongo config commands.; | |
mongo --host mongo -u mongoadmin -p secret --authenticationDatabase admin mymongodb --eval 'db.createUser({ \"user\": \"mongouser\", \"pwd\": \"secret\", \"roles\": [ \"readWrite\", \"dbAdmin\" ] })'; | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying a similar thing, it says unknown host mongo