02 / 11

What are the top-level sections in a docker-compose.yml file, and what does each do? (Demonstrates familiarity with the file's structure.)

A Compose file defines three main sections:

  1. 1

    Services: Specifies the containers to run and their runtime configuration (image, build context, ports, environment variables, volumes, depends_on, healthcheck, etc.).

  2. 2

    Volumes: Declares named persistent storage volumes that can be attached to services.

  3. 3

    Networks: Defines virtual networks for container communication, allowing services to resolve each other by name for easy internal communication