-
Notifications
You must be signed in to change notification settings - Fork 23
/
docker-compose.yml
82 lines (79 loc) · 3.46 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
services:
tester:
# 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.test
image: tester
container_name: tester
env_file: .env.test
depends_on:
- mongo
- redis
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}'
depends_on:
- mongo
- redis
mongo:
# To create this service, Compose will pull the mongo
image: mongo:7.0.4
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'
command: mongod --bind_ip_all
volumes:
- ./.resources/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
- ./.resources/restore-mongo.sh:/docker-entrypoint-initdb.d/restore-mongo.sh:ro
- ./.resources/wimm-db-dump:/db-dump
# 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
redis:
image: redis:7.2.3
container_name: redis
restart: unless-stopped
env_file: .env
ports:
- '${REDIS_PORT}:6379'
command: redis-server --bind localhost --bind 0.0.0.0 --save 20 1 --loglevel warning --requirepass ${REDIS_PASSWORD}
volumes:
- cache:/data/cache
# 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