mhassaankhokhar
mhassaankhokhar

Reputation: 74

Why containers are called services in docker compose?

I am creating containers using docker-compose. The technical name for the container is service in docker compose.

version: "3.9"
services:
  web:
    build: .
    ports:
      - "1026:5000"
    depends_on: 
      - redis
    volumes:
      - vol1:/code
  redis:
    image: "redis:alpine"
    container_name: db
volumes:
  vol1:

Upvotes: 0

Views: 73

Answers (1)

Chris Becke
Chris Becke

Reputation: 36026

A service is a specification for running containers. A service persists while, at any point in time, there might be 0, 1, or many containers that are service tasks, or replicas.

With compose, you can scale the number of replicas of a service using the scale keyword. there are now many containers, but still one service to manage them. If containers shut down, the service restart policy can have rules about restarting the service. This will cause new containers to be created. Each stopped container can be examined for its own crash - or success - logs. But again, the service is the single contact point that can retrieve the list of containers, their status and so on.

Upvotes: 2

Related Questions