liveBook · Manning

Docker-compose.yml

As explained in Build Financial Software with Generative AI (From Scratch)

A docker-compose.yml file is a YAML configuration file that defines services, networks, volumes, and related settings for Docker Compose applications.

A docker-compose.yml file is a YAML configuration file for managing a multi-container application from one place. It declares services and their runtime-facing settings, so related components such as an API, database, proxy, dashboard, or test server can be built and started together rather than managed separately. section 3.2 section 4.4.2

Start small: define one service, point its build configuration at the service folder and Dockerfile, and map a host port to the container port. Run docker-compose build and docker-compose up, then verify the service through its browser endpoint. Add services incrementally once the first container works. section 3.2 section 4.4.2

A service definition can coordinate several practical concerns:

  • Build settings identify the build context and Dockerfile for a service image. section 4.4.2
  • Port mappings expose a container service through a chosen host port; a collision can require stopping the conflicting process or changing the mapping. section 3.2.1
  • Volumes map local directories into a container, allowing WireMock mappings and files to change without rebuilding the image. section 6.5.1
  • Build arguments can pass configuration into an image build, such as a browser-visible API base URL. section 6.8

WireMock service with editable mappings

A WireMock service builds from a dedicated wiremock Dockerfile, maps local __files and mappings directories into the container, and exposes host port 8081 to container port 8080. This separates image building from runtime configuration and lets local stub definitions be updated without rebuilding. section 6.5.1

Use container names rather than localhost when one container connects to another. localhost can point at the current container rather than the database container. Keep database credentials aligned between the Compose configuration and application code when diagnosing authentication failures. section 3.3.2

Listing 6.19 Updates to docker-compose.yml
  wiremock:
    build:
      context: ./wiremock
      dockerfile: Dockerfile
    volumes:                                       #1
      - ./wiremock/__files:/home/wiremock/__files   #1
      - ./wiremock/mappings:/home/wiremock/mappings #1
    ports:
      - 8081:8080

This service definition shows a build target, two local-to-container volume mappings, and a port mapping in one compact configuration. section 6.5.1

How Build Financial Software with Generative AI (From Scratch) covers it

How deep it goes
Works through service builds, ports, volumes, build arguments, and common connection failures rather than Compose internals.
Examples
Uses CloudBeaver, a FastAPI files API, WSO2 API Manager, WireMock, PostgreSQL, and a dashboard as service examples.
What it assumes
Starts from a single container while introducing Dockerfile references, build contexts, and port mappings.
What you can do after
Operate/configure it to build and start services, expose ports, mount local files, and resolve port or container-address conflicts.
How it connects
Connects Docker Compose with Dockerfile, containers, ports, volumes, build arguments, environment variables, WireMock, and PostgreSQL.

Also explained in

Compare how 4 books explain docker-compose.yml →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Financial Software with Generative AI (From Scratch). The section links point to the parts of the book it draws on.