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 a Docker Compose application. It brings service settings into one place, making a multicontainer application easier to configure and run together. section 3.2

Start with one service and verify it before adding more. A service can use an existing image or build from a Dockerfile. Port mappings make a service available on the host; volumes can make local directories available inside a container. section 3.2 section 4.4.2 section 6.5.1

services:
  api:
    build: 
      context: ./api
      dockerfile: Dockerfile  
    ports:
      - 8000:8000

This API service builds from the Dockerfile in ./api and maps host port 8000 to container port 8000. section 4.4.2

From the directory containing the file, run docker-compose build and docker-compose up. For the API example, visit http://localhost:8000/files/ to check the response. The version field in older generated examples is obsolete and can be removed. section 4.4.2 section 3.2.1

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

WireMock maps local stub files and mappings into the container. Each volume mapping names the host directory first and the container directory second, allowing local mapping changes without repeatedly rebuilding. section 6.5.1

Keep image-building instructions in a Dockerfile and runtime mappings in the Compose file. Copying mappings into an image is another option when the image must be distributed with those mappings. section 6.5.1

Dashboard and mock API

A dashboard service passes NEXT_PUBLIC_API_URL as a build argument and maps host port 4000 to container port 3000. Because its API calls run in the browser, the example uses localhost:8081 for WireMock rather than the internal address wiremock:8080. section 6.8

If a service does not work, check its surroundings as well as its configuration:

  • If a host port is already allocated, stop the conflicting process or change the port mapping. section 3.2.1
  • For a database connection from a container, use the container name rather than localhost, and check that the configured credentials match the application’s credentials. section 3.3.2
  • Review generated configuration and test small changes; a generated file is only a starting point. section 3.2

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

How deep it goes
Walks through service builds, ports, volumes, build arguments, and troubleshooting, starting with one container before adding services.
Examples
Uses CloudBeaver, a FastAPI service, WireMock mappings, and a dashboard to demonstrate configuration.
What you can do after
Operate/configure Docker Compose services, verify their endpoints, and troubleshoot port or database connection problems.
How it connects
Connects Docker Compose with Dockerfiles, containers, port mapping, volumes, and database connection settings.

Also explained in

Compare how 5 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.