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




