Compose File Format - docker/compose

The docker-compose.yml file is a YAML file used to configure Docker applications with services, networks, and volumes. The latest version of the Compose file format is defined by the Compose Specification and is implemented by Docker Compose 1.27.0+.

Here are the main elements of the Compose file format:

  1. services: This section is used to define the services (containers) that make up the application. Each service is defined as a separate dictionary under the services key.

Example:

services:
web:
image: my-web-image
ports:
- "80:80"
  1. version: This key is used to specify the version of the Compose file format. It is optional and should be omitted in the latest versions of Compose.

Example:

version: "3.8"
  1. networks: This section is used to define the networks that the application will use. Networks are defined as a separate dictionary under the networks key.

Example:

networks:
my-network:
driver: bridge
  1. volumes: This section is used to define the volumes that the application will use. Volumes are defined as a separate dictionary under the volumes key.

Example:

volumes:
my-volume:
  1. configs: This section is used to define the configs that the application will use. Configs are defined as a separate dictionary under the configs key.

Example:

configs:
my-config:
file: my-config.txt
  1. secrets: This section is used to define the secrets that the application will use. Secrets are defined as a separate dictionary under the secrets key.

Example:

secrets:
my-secret:
file: my-secret.txt

For more information on the Compose file format, refer to the following resources:

Note: Compose V1 is no longer supported as of June 2023. It is recommended to use Compose V2, which uses the Compose Specification for project definition and ignores the version field in YAML.