Targeting multiple environments A typical use case is when you define multiple compose files so you can target multiple environments,
like production, staging, CI, or development. To support these differences, you can split your
Compose configuration into multiple files, as shown in Figure 6-12.
122
CHAPTER 5 | Designing and Developing Multi-Container and Microservice-Based .NET Applications
Figure 6-12. Multiple docker-compose files overriding values in the base docker-compose.yml file You can combine multiple docker-compose*.yml files to handle different environments. You start with
the base docker-compose.yml file. This base file contains the base or static configuration settings that
do not change depending on the environment. For example, the eShopOnContainers app has the
following docker-compose.yml file (simplified with fewer services) as the base file.
#docker-compose.yml (Base)
version:
'3.4'
services:
basket-api:
image:
eshop/basket-api:${TAG:-latest}
build:
context:
.
dockerfile:
src/Services/Basket/Basket.API/Dockerfile
depends_on:
- basketdata
- identity-api
- rabbitmq
catalog-api:
image:
eshop/catalog-api:${TAG:-latest}
build:
context:
.
dockerfile:
src/Services/Catalog/Catalog.API/Dockerfile
depends_on:
- sqldata
- rabbitmq
marketing-api:
image:
eshop/marketing-api:${TAG:-latest}
build:
context:
.
dockerfile:
src/Services/Marketing/Marketing.API/Dockerfile
depends_on:
- sqldata
- nosqldata
- identity-api
- rabbitmq
webmvc:
123
CHAPTER 5 | Designing and Developing Multi-Container and Microservice-Based .NET Applications
image:
eshop/webmvc:${TAG:-latest}
build:
context:
.
dockerfile:
src/Web/WebMVC/Dockerfile
depends_on: