Docker Course
Docker
/
Intermediate

docker-compose.yml

Definition

The declarative YAML configuration file used by Docker Compose. It dictates exactly how the services, networks, and volumes should be built and interconnected.

Explain Like I'm New

The master blueprint for the entire application stack. It specifies that the Web service needs port 80, the Database service needs a volume, and that the Web service cannot start until the Database is fully booted.

Real World Example

A file that outlines: ```yaml services: db: image: postgres:15 api: build: . ports: ["3000:3000"] depends_on: ["db"] ```

Common Use Cases

  • •Infrastructure as Code
  • •Onboarding developers

Interview Questions

basic

  • What is the default filename Docker Compose looks for when you run `docker-compose up`?

intermediate

  • What does the `depends_on` keyword actually do in a compose file?

Flash Cards

Question

Default filename?

Click to reveal answer
Answer

`docker-compose.yml` or `compose.yaml`.

Question

What does depends_on do?

Click to reveal answer
Answer

It controls the startup order. If the `api` service depends on `db`, Compose guarantees that the Database container will be sent the 'Start' command before the API container. (Note: It does not wait for the DB to be *ready* for traffic, only that the container started).