-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.yml
57 lines (54 loc) · 2.49 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
version: '3.9'
services:
app:
# This defines the configuration options, including the context and dockerfile,
# that will be applied when Compose builds the application image.
build:
# This defines the build context for the image build — in this case, the current project directory.
context: .
# This specifies the Dockerfile in your current project directory as the file
dockerfile: Dockerfile
image: app
container_name: app
# This defines the restart policy. The default is no,
# but we have set the container to restart unless it is stopped.
restart: unless-stopped
env_file: .env
ports:
# This maps port from .env on the host to same port number on the container.
- '$PORT:$PORT'
links:
- mongo
depends_on:
- mongo
mongo:
# To create this service, Compose will pull the mongo
image: mongo:6.0.3
container_name: 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:
- ./addons/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:
cache:
driver: local