1- version : ' 3.9'
2-
31services :
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
416 app :
517 # This defines the configuration options, including the context and dockerfile,
618 # that will be applied when Compose builds the application image.
@@ -9,26 +21,23 @@ services:
921 context : .
1022 # This specifies the Dockerfile in your current project directory as the file
1123 dockerfile : Dockerfile
12- image : app
13- container_name : app
24+ image : blogs- app:latest
25+ container_name : blogs- app
1426 # This defines the restart policy. The default is no,
1527 # but we have set the container to restart unless it is stopped.
1628 restart : unless-stopped
1729 env_file : .env
1830 ports :
1931 # 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}'
2433 depends_on :
2534 - mongo
2635 - redis
2736
2837 mongo :
2938 # To create this service, Compose will pull the mongo
3039 image : mongo:7.0.4
31- container_name : mongo
40+ container_name : blogs- mongo
3241 restart : unless-stopped
3342 # This tells Compose that we would like to add environment variables
3443 # from a file called .env, located in our build context.
@@ -38,11 +47,11 @@ services:
3847 # a root user in the admin authentication database and ensure that authentication is enabled
3948 # when the container starts. We have set MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD
4049 # 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}
4453 ports :
45- - ' $DB_PORT:27017'
54+ - ' ${ DB_PORT} :27017'
4655 volumes :
4756 - ./addons/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
4857 # The named volume dbdata will persist the data stored in Mongo’s default data directory, /data/db.
@@ -51,12 +60,12 @@ services:
5160
5261 redis :
5362 image : redis:7.2.3
54- container_name : redis
63+ container_name : blogs- redis
5564 restart : unless-stopped
5665 env_file : .env
5766 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}
6069 volumes :
6170 - cache:/data/cache
6271
0 commit comments