1
- version : ' 3.9'
2
-
3
1
services :
2
+ tester :
3
+ # This defines the configuration options, including the context and dockerfile,
4
+ # that will be applied when Compose builds the application image.
5
+ build :
6
+ # This defines the build context for the image build — in this case, the current project directory.
7
+ context : .
8
+ # This specifies the Dockerfile in your current project directory as the file
9
+ dockerfile : Dockerfile.test
10
+ image : blogs-tester:latest
11
+ container_name : blogs-tester
12
+ env_file : .env.test
13
+ depends_on :
14
+ - mongo
15
+ - redis
4
16
app :
5
17
# This defines the configuration options, including the context and dockerfile,
6
18
# that will be applied when Compose builds the application image.
@@ -9,26 +21,23 @@ services:
9
21
context : .
10
22
# This specifies the Dockerfile in your current project directory as the file
11
23
dockerfile : Dockerfile
12
- image : app
13
- container_name : app
24
+ image : blogs- app:latest
25
+ container_name : blogs- app
14
26
# This defines the restart policy. The default is no,
15
27
# but we have set the container to restart unless it is stopped.
16
28
restart : unless-stopped
17
29
env_file : .env
18
30
ports :
19
31
# This maps port from .env on the host to same port number on the container.
20
- - ' $PORT:$PORT'
21
- links :
22
- - mongo
23
- - redis
32
+ - ' ${PORT}:${PORT}'
24
33
depends_on :
25
34
- mongo
26
35
- redis
27
36
28
37
mongo :
29
38
# To create this service, Compose will pull the mongo
30
39
image : mongo:7.0.4
31
- container_name : mongo
40
+ container_name : blogs- mongo
32
41
restart : unless-stopped
33
42
# This tells Compose that we would like to add environment variables
34
43
# from a file called .env, located in our build context.
@@ -38,11 +47,11 @@ services:
38
47
# a root user in the admin authentication database and ensure that authentication is enabled
39
48
# when the container starts. We have set MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD
40
49
# using the values from our .env file, which we pass to the db service using the env_file option.
41
- - MONGO_INITDB_ROOT_USERNAME=$DB_ADMIN
42
- - MONGO_INITDB_ROOT_PASSWORD=$DB_ADMIN_PWD
43
- - MONGO_INITDB_DATABASE=$DB_NAME
50
+ - MONGO_INITDB_ROOT_USERNAME=${ DB_ADMIN}
51
+ - MONGO_INITDB_ROOT_PASSWORD=${ DB_ADMIN_PWD}
52
+ - MONGO_INITDB_DATABASE=${ DB_NAME}
44
53
ports :
45
- - ' $DB_PORT:27017'
54
+ - ' ${ DB_PORT} :27017'
46
55
volumes :
47
56
- ./addons/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
48
57
# The named volume dbdata will persist the data stored in Mongo’s default data directory, /data/db.
@@ -51,12 +60,12 @@ services:
51
60
52
61
redis :
53
62
image : redis:7.2.3
54
- container_name : redis
63
+ container_name : blogs- redis
55
64
restart : unless-stopped
56
65
env_file : .env
57
66
ports :
58
- - ' $REDIS_PORT:6379'
59
- command : redis-server --save 20 1 --loglevel warning --requirepass $REDIS_PASSWORD
67
+ - ' ${ REDIS_PORT} :6379'
68
+ command : redis-server --save 20 1 --loglevel warning --requirepass ${ REDIS_PASSWORD}
60
69
volumes :
61
70
- cache:/data/cache
62
71
0 commit comments