Some containers need one tiny config file, a few lines at most. Instead of keeping a separate file next to compose.yaml, you can define it inline with a top level configs entry.
services:
web:
image: nginx:alpine
configs:
- source: app_conf
target: /etc/app.conf
configs:
app_conf:
content: |
level=${LOG_LEVEL:-info}
listen=8080
Compose writes that text into the container at /etc/app.conf. Variables are filled in like anywhere else in the file, which makes it a neat way to generate a config from your .env values. Running docker compose config shows the final text.
A config can also come from file: or environment: instead of content:. I’d keep the inline form for short files; a long nginx config is easier to read and diff as its own file.
Watch out with dollar signs. Since Compose interpolates the content, a literal $ for the app has to be written as $$. Nginx variables like $host are the classic case. Also expect a config to be read only inside the container, so it is not the place for a file the app wants to rewrite.
Further reading: Compose file reference: configs