Setting up MongoDB with Docker
04/05/2019 — 1 Min Read — In Development
One of my friends asked for help setting up a MongoDB with docker, so I threw together this gist. This sets up mongo with authentication enabled, which is really important (and overlooked in many tutorials). It also includes a container you can use to do nightly backups to S3.
| version: "2" | |
| services: | |
| mongo: | |
| image: mckernanin/mongo-auth:4.0.8 | |
| environment: | |
| AUTH: "yes" | |
| MONGODB_ADMIN_USER: admin | |
| MONGODB_ADMIN_PASS: '**********' # set your admin password here | |
| MONGODB_APPLICATION_DATABASE: appname # give the db a name | |
| MONGODB_APPLICATION_USER: application | |
| MONGODB_APPLICATION_PASS: '**********' # set your application password here | |
| ports: | |
| - 27017:27017 | |
| volumes: | |
| - ~/.mongo:/data/db # this persists your mongo data to disk outside of docker | |
| # mongo-backup: # automated backups to s3 | |
| # image: lgatica/mongodump-s3 | |
| # environment: | |
| # MONGO_URI: mongodb://application:**********@mongodb/appname # connection string based on above config | |
| # AWS_ACCESS_KEY_ID: '**********' # aws access key | |
| # AWS_SECRET_ACCESS_KEY: '**********' # aws secret key | |
| # AWS_DEFAULT_REGION: us-east-2 # aws region | |
| # S3_BUCKET: '**********' # aws bucket name | |
| # BACKUP_CRON_SCHEDULE: 0 2 * * * | |
| # S3_PATH: '**********' # aws bucket path | |
| # links: | |
| # - mongo:mongodb |