liveBook · Manning

Multicontainer configuration

As explained in Rust Servers, Services, and Apps

A multicontainer configuration is a declarative specification for building and running an application composed of multiple containers.

A multicontainer configuration declaratively defines how an application’s containers are built and run. Docker Compose stores service build instructions, storage, environment variables, networks, dependencies, and restart behavior in one YAML file. section 12.5

version: '3'
services:
  db:                                         #1
    container_name: tutor-postgres
    restart: always
    image: postgres:latest
    environment:
     - POSTGRES_USER=postgres
     - POSTGRES_PASSWORD=postgres
     - POSTGRES_DB=ezytutors
    volumes:
     - tutor-data:/var/lib/postgresql/data
     - ./c12-data/initdb.sql:/docker-entrypoint-initdb.d/initdb.sql
     - ./c12-data/init-tables.sql:/docker-entrypoint-initdb.d/init-tables.sql
    ports:
     - 5432:5432
    networks:
     - tutor-network
  api:                                       #2
    restart: on-failure
    container_name: tutor-webservice
    build:                                   #3
      context: ./
      dockerfile: Dockerfile-tutor-webservice
      network: host
    environment:                             #4
     - DATABASE_URL=${DATABASE_URL}
     - HOST_PORT=${HOST_PORT}
    depends_on:
     - db                                    #5
    ports:
     - ":3000:3000"                          #6
    networks:
     - tutor-network                         #7
volumes:
        tutor-data:
networks:
        tutor-network:

The configuration declares a PostgreSQL db service and an api service, connecting them through shared networking and persistent database storage. section 12.5

EzyTutors service stack

A Compose file defines tutor-postgres from the postgres:latest image and tutor-webservice from Dockerfile-tutor-webservice. Environment variables provide DATABASE_URL and HOST_PORT; the database uses a named volume and initialization scripts. Commands such as docker compose build api, docker compose up -d, and curl localhost:3000/tutors/ build, start, and verify the stack. section 12.5

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains declarative fields, dependencies, networking, persistence, environment setup, build commands, and endpoint verification.
Examples
Uses the EzyTutors API, PostgreSQL initialization scripts, tutor-data persistence, network inspection, and a tutors endpoint request.
What you can do after
Operate/configure a two-container application stack with Docker Compose and verify its API response.
How it connects
Connects Docker Compose with Docker containers, YAML, environment variables, Docker networks, Docker volumes, and PostgreSQL.

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.