Skip to content

Multi-service container orchestration

Multi-service container orchestration refers to the process of defining and running multiple connected containerized applications as a single system.^[600-developer__docker__docker-compose__docker-compose-01.md]

Overview

This approach allows for the simultaneous startup of multiple container images, rather than managing them individually.^[600-developer__docker__docker-compose__docker-compose-01.md] It is commonly used to manage groups of services that interact with one another, such as a web server and a database.^[600-developer__docker__docker-compose__docker-compose-01.md]

Implementation with Docker Compose

The primary tool for achieving this level of orchestration in a local development or single-host environment is Docker Compose.^[600-developer__docker__docker-compose__docker-compose-01.md] Users define the configuration, services, and dependencies in a file typically named docker-compose.yml.^[600-developer__docker__docker-compose__docker-compose-01.md]

To execute the orchestration defined in this file, the standard command is:

docker-compose up
Using the -d flag allows the services to start in the background (detached mode).^[600-developer__docker__docker-compose__docker-compose-01.md]

Example Configuration

A typical orchestration scenario involves linking an application to a database. The following example defines a service for a MySQL database and a separate service for Adminer (a database management tool).^[600-developer__docker__docker-compose__docker-compose-01.md]

version: '3.1'

services:
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: 'root'
      MYSQL_DATABASE: 'db'
      MYSQL_USER: 'tommy'
      MYSQL_PASSWORD: 'tommy'

  adminer:
    image: adminer
    restart: always
    ports:
      - 8888:8080

In this configuration: * The db service utilizes the MySQL 5.7 image and sets up initial credentials and database names via environment variables^[600-developer__docker__docker-compose__docker-compose-01.md]. * The adminer service runs a database UI, mapping port 8080 inside the container to port 8888 on the host machine^[600-developer__docker__docker-compose__docker-compose-01.md]. * Both services are configured with a restart policy to ensure they recover automatically if they fail^[600-developer__docker__docker-compose__docker-compose-01.md].

Installation Methods

To use Docker Compose for orchestration, it must be installed on the host system. Common installation methods include:

  • YUM Installation (RHEL/CentOS):
    1. Install EPEL release.
    2. Install python-pip.
    3. Use pip to install docker-compose.^[600-developer__docker__docker-compose__docker-compose-01.md]
  • Binary Installation:
    1. Download the binary from the GitHub repository releases.
    2. Apply executable permissions to the binary.^[600-developer__docker__docker-compose__docker-compose-01.md]

Sources

  • 600-developer__docker__docker-compose__docker-compose-01.md