brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Compose configs with content: write a small config file inline

Docker
~/tips/tip-docker-compose-configs-content

content: |

Put a short config file inside the Compose file instead of next to it.

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

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link