Capturing service definitions

Services can be defined in any order in the Compose file. To make it easier to read, I prefer to start with the simplest services, which have no dependencies—infrastructure components, such as the message queue, reverse proxy, and databases.

Docker Compose files are conventionally called docker-compose.yml, and they start with an explicit statement of the API version; the latest is version 3.7. Application resources are defined at the top level—this is a template Compose file with sections for services, networks, and volumes:

 version: '3.7'

  services:
    ...

  networks:
    ...

  volumes:
    ...
The Docker Compose specification is documented at the Docker website at https://docs.docker.com/compose/compose-file/. This lists the full specification for all supported versions, and the changes between the versions.

All resources need a unique name, and the name is how resources refer to other resources. Services may have a dependency on networks, volumes, and other services, which are all captured by name. The configuration for each resource is in its own section, and the attributes available are broadly the same as the respective create command in the Docker CLI, such as docker network create and docker volume create.

In this chapter, I'll build a Compose file for the distributed NerdDinner application and show you how to use Docker Compose to manage the application. I'll start my Compose file with the common services first.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.12.232