Docker Course
Docker
/
Beginner

Services

Definition

The top-level concept in a Docker Compose file. A 'service' defines a computing component of an application, prescribing which image to use, how many container instances to run, and its configuration.

Explain Like I'm New

The individual 'Apps' inside the compose file. A database is one service. The API is another service.

Real World Example

In the command `docker-compose restart api`, the word 'api' refers to the specific Service block defined in the YAML file. Compose will only restart the containers associated with that specific service.

Common Use Cases

  • •Application architecture
  • •Targeted commands

Interview Questions

basic

  • Can one Compose 'Service' actually spin up multiple identical containers simultaneously?

intermediate

  • What happens if you run `docker-compose up --scale api=3`?

Flash Cards

Question

Multiple containers?

Click to reveal answer
Answer

Yes. A Service is just the definition. You can tell Compose to scale that service to run 5 identical container replicas simultaneously.

Question

Scale command?

Click to reveal answer
Answer

Docker Compose will read the `api` service blueprint, and instantly spin up 3 identical API containers to handle load balancing.