Test your understanding of the concepts covered in the Multi-Container Environments chapter.
Q1. Why is creating a user-defined bridge network (`docker network create`) preferred over relying on the default bridge network when connecting multiple containers?
Explanation
Containers on user-defined bridge networks can automatically resolve each other's container or service names to IP addresses via Docker DNS, providing secure network isolation.
Q2. Which Docker Compose file attribute ensures that dependent containers (such as a database service `es`) start before an application service `web`?
Explanation
The `depends_on` directive in `docker-compose.yml` specifies dependency ordering, instructing Compose to create and start prerequisite services first.
Q3. Which command starts all services defined in a `docker-compose.yml` file in background (detached) mode?
Explanation
Running `docker compose up -d` creates the network, volumes, and containers defined in your stack and runs them in detached mode.
Q4. What command stops containers and networks created by Docker Compose AND removes named persistent volumes?
Explanation
`docker compose down` stops containers and networks, while adding `-v` also removes named volumes declared under the `volumes:` block.