Compose Files
Let's examine a sample Docker Compose YAML file.
Compose uses YAML files to define microservices applications. We call them Compose files, and Compose expects you to name them compose.yaml
or compose.yml
. However, you can use the -f
flag with the docker compose
command to specify files with arbitrary names.
Docker Compose file for a multi-service application
Here is the Compose file we’ll be using. It’s called compose.yaml
and is in the multi-container
folder.
Press + to interact
services: <<---- Microservices are defined in the "services" blockweb-fe: <<---- This block defines the web front-end microservicedeploy:replicas: 1build: .command: python app.pyports:- target: 8080published: 5001networks:- counter-netvolumes:- type: volumesource: counter-voltarget: /appredis: <<---- This block defines the Redis back-end microservicedeploy:replicas: 1image: "redis:alpine"networks:counter-net:networks: <<---- Networks are defined in this blockcounter-net:volumes: <<---- Volumes are defined in this blockcounter-vol:
The first thing to note is that the file has three top-level keys with a block of code beneath each:
- services
- networks
- volumes
More top-level keys exist, but this app only uses the three in the list.
Let’s have a closer look at each.
Defining the web-fe
service
The top-level services
key is mandatory and is where you define application microservices. This app has two microservices called ...
Access this course and 1400+ top-rated courses and projects.