-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker-compose.yml
33 lines (31 loc) · 1.7 KB
/
docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
version: '3.7'
services:
mongo:
# To create this service, Compose will pull the mongo
image: mongo:4.2.5
container_name: calamus_mongo
restart: unless-stopped
# This tells Compose that we would like to add environment variables
# from a file called .env, located in our build context.
env_file: .env
environment:
# MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD together create
# a root user in the admin authentication database and ensure that authentication is enabled
# when the container starts. We have set MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD
# using the values from our .env file, which we pass to the db service using the env_file option.
- MONGO_INITDB_ROOT_USERNAME=$DB_ADMIN
- MONGO_INITDB_ROOT_PASSWORD=$DB_ADMIN_PWD
- MONGO_INITDB_DATABASE=$DB_NAME
ports:
- "$DB_PORT:27017"
volumes:
- ./mongodb/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
# The named volume dbdata will persist the data stored in Mongo’s default data directory, /data/db.
# This will ensure that you don’t lose data in cases where you stop or remove containers.
- dbdata:/data/db
# Our top-level volumes key defines the volumes dbdata.
# When Docker creates volumes, the contents of the volume are stored in a part of the host filesystem, /var/lib/docker/volumes/, that’s managed by Docker.
# The contents of each volume are stored in a directory under /var/lib/docker/volumes/ and get mounted to any container that uses the volume.
# In this way, the data that our users will create will persist in the dbdata volume even if we remove and recreate the db container.
volumes:
dbdata: