One compose file for the stack and a second small one for the changes on a particular machine keeps the main file clean. The order of the -f flags is the whole trick.
Compose merges the files in the order you give them, and later files can merge into, override or add to earlier ones. The first file is the base, and relative paths in every file are resolved from the base file’s location.
docker compose -f compose.yaml -f compose.prod.yaml up -d
The docs describe how the merge works. Single-value options like image or command are replaced by the later file. Lists such as ports and expose are concatenated. environment and labels merge by name, with the override winning, and volumes merge by mount path.
A small override could look like this:
services:
app:
image: example/app:2.0
ports:
- "8081:80"
Before running anything, look at the result with docker compose -f compose.yaml -f compose.prod.yaml config. It prints the merged file, so you see what Compose will really do.
Mind the default: with no -f, Compose reads compose.yaml and also compose.override.yaml if it exists in the same folder. as soon as you pass -f yourself, you decide the list, so add the override file yourself when you want it.
Further reading: Merge Compose files