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: format: raw passes dollar signs in an env file through untouched

Security
~/tips/tip-compose-env-file-format-raw

format: raw

Reads an env file without interpolation, so dollar signs and quotes arrive unchanged.

Compose interpolates the values in an env_file too, so a value with a dollar sign in it, such as a generated password, can come out different from what the file says.

The long form of env_file takes a format key:

services:
  app:
    image: example/app:latest
    env_file:
      - path: ./app.env
        format: raw

With format: raw, Compose reads the key=value pairs without interpolation, so quotes and $ signs go to the container exactly as written. In app.env this stays as it is:

DB_PASSWORD=pa$sw0rd'x

In the compose file itself you need $$ for a literal dollar. Inside a raw env file you write the value once and it arrives once.

Caveat: raw also means no variables. A line like URL=http://${HOST}/api is not expanded either, so keep the default format for files that rely on that. To check what the container really gets, run docker compose run --rm app env, and remember that it prints your secrets to the terminal.

The project’s .env file is a separate job. Compose reads it for substitutions inside the compose file, while env_file entries feed the container.

Further reading: Compose container spec: env_file

More Security tips tcpdump -nn -r capture.pcap port 53 mkcert -install Strict-Transport-Security: max-age=0 Referrer-Policy: strict-origin-when-cross-origin wp super-admin list All Security tips (79) All topics

Link