Challenge your understanding of Docker Compose features, configuration, and best practices for orchestrating multi-container applications. This quiz will help you assess key concepts, YAML syntax, networking, and common pitfalls in multi-container setups.
In a Docker Compose YAML file, how can you ensure that the 'web' service only starts after the 'db' service has been started, assuming you want to control service startup order?
Explanation: The 'depends_on' key specifies service dependencies to control startup order, making it the correct option for managing dependencies in Compose. 'wait_for' and 'priority' are not recognized configuration keys in standard Compose files. Simply changing the order of services in the YAML does not establish dependency relationships.
When multiple services are defined in a Docker Compose file without specifying custom networks, what is the default networking behavior between them?
Explanation: By default, Compose creates a single network for the entire application and attaches each service to it, allowing inter-service communication via service names. Isolated networks for services do not happen automatically. Explicit bridge network configuration is not needed unless you require customization, and 'links' is deprecated and unnecessary for basic communication.
Which option correctly attaches a persistent named volume to the '/data' directory inside a service container in Docker Compose?
Explanation: The correct Compose syntax for named volumes uses the 'volumes' key and the format 'name:/path', such as 'data_volume:/data'. 'storage', 'mounts', and 'binds' are not recognized keys or are improperly formatted in Compose YAML files. The provided distractors contain incorrect keywords or unsupported options.
How can you run three instances of the 'worker' service defined in a Docker Compose file, assuming the YAML is correctly configured?
Explanation: The '--scale' command-line flag is used during Compose deployment to run multiple instances of a service. The 'replicas' option is relevant only for some other orchestration platforms, not standard Compose. Changing the service name or adding 'count' does not implement scaling in Compose.
In Docker Compose, how can you set an environment variable called 'APP_ENV' with the value 'production' for a specific service?
Explanation: Setting environment variables for a service in Compose is done with the 'environment' key and the format 'VAR=value'. Adding 'export' or 'set' commands or using unsupported keys like 'env_vars' in YAML is not valid. These alternatives would not inject environment variables correctly.