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" block
web-fe: <<---- This block defines the web front-end microservice
deploy:
replicas: 1
build: .
command: python app.py
ports:
- target: 8080
published: 5001
networks:
- counter-net
volumes:
- type: volume
source: counter-vol
target: /app
redis: <<---- This block defines the Redis back-end microservice
deploy:
replicas: 1
image: "redis:alpine"
networks:
counter-net:
networks: <<---- Networks are defined in this block
counter-net:
volumes: <<---- Volumes are defined in this block
counter-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.