Skip to content

Use mapping syntax for environment variables in docker-compose example#4186

Open
isidroas wants to merge 3 commits into
dgtlmoon:masterfrom
isidroas:fix-compose
Open

Use mapping syntax for environment variables in docker-compose example#4186
isidroas wants to merge 3 commits into
dgtlmoon:masterfrom
isidroas:fix-compose

Conversation

@isidroas

@isidroas isidroas commented May 26, 2026

Copy link
Copy Markdown
  • Convert environment entries from list syntax to key/value mapping syntax
  • Keep existing variable values and behavior unchanged

- Convert environment entries from list syntax to key/value mapping syntax
- Keep existing variable values and behavior unchanged
@dgtlmoon

Copy link
Copy Markdown
Owner

is it the whole YML that needs this change?

@isidroas

Copy link
Copy Markdown
Author

It is not required, but I would be fine with converting the rest as well so the whole compose file keeps a consistent style

@dgtlmoon

Copy link
Copy Markdown
Owner

It is not required, but I would be fine with converting the rest as well so the whole compose file keeps a consistent style

more consistent more better :) yes please

isidroas added 2 commits May 31, 2026 11:48
modified with:
$ sed -i -E 's/([[:space:]]+- [^=:]+)=/\1: /' docker-compose.yml
@isidroas

Copy link
Copy Markdown
Author

Done. The disadvantage is that it needs quoting for some values

@AmirF194 AmirF194 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation makes sense, mapping syntax does read better than the list form, and the genuinely tricky part is handled well: every value that YAML would coerce is quoted correctly. I checked each one and they matter. Unquoted ALLOW_FILE_URI: False would fold to the string "false" (lowercase, wrong), and HIDE_REFERER/DISABLE_VERSION_CHECK: true and LISTEN_HOST: :: are all coercion or parse hazards, so quoting them as 'False', 'true', '::' preserves the intended strings. That is the part people usually get wrong. The embedded-colon values (ws://...:3000, http://...:4444/wd/hub, etc.) are safe unquoted because each colon is followed by a non-space, and bare integers are fine since compose stringifies them.

One blocking issue: outside the selenium block, most of the converted lines keep the leading - , so they become - KEY: value rather than KEY: value. That is a list item whose value is a map, not mapping syntax, and docker compose rejects it. I reproduced it on compose v5.0.2:

services.changedetection.environment.[0]: unexpected type map[string]interface{}

It looks like a mechanical = to : substitution that kept the list markers, whereas the selenium block was hand-edited correctly with the dashes removed. Since this file is a copy-paste-and-uncomment example, an uncommented line that fails validation is a real problem, and right now the file is internally inconsistent (selenium correct, the rest not). Dropping the - on the converted lines in the changedetection and sockpuppet-browser blocks would make them match selenium and the PR title.

Two optional notes: the description says behavior is unchanged, but two values actually do change, both arguably for the better. NO_PROXY in list form kept its literal quote characters, and mapping form strips them; CHROME_OPTIONS moved from | (newline-separated) to > (space-separated), which is what Chrome flags actually want. Worth a line in the description. And LISTEN_HOST: '::' is quoted while the alternate LISTEN_HOST: 0.0.0.0 is not, both correct, just slightly inconsistent to read.

@dgtlmoon dgtlmoon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Unfortunately this conversion isn't quite right and I don't think we should merge it as-is.

Most of the file ends up as invalid syntax. The change produces a hybrid like:

environment:
  - PORT: 5000
  - LOGGER_LEVEL: TRACE

That's neither valid form. Docker Compose accepts either:

  • List syntax: - PORT=5000 (dash, =, string), or
  • Mapping syntax: PORT: 5000 (no dash, :)

- PORT: 5000 is a list of single-key maps, which Compose does not accept for environment:, so uncommenting these would error out — the "behavior unchanged" goal isn't actually met.

It's also inconsistent — only the selenium block at the bottom was converted correctly (dashes removed):

environment:
  VNC_NO_PASSWORD: 1
  SCREEN_WIDTH: 1920

...while the rest kept the - prefix.

Minor: mapping syntax also changes YAML typing. Some values were quoted (HIDE_REFERER: 'true'), others left bare (FETCH_WORKERS: 10) — this is exactly the quoting subtlety that makes the plain KEY=value list form (always a string) the safer default for a copy-paste example file.

If you'd like to pursue this, could you (a) drop the - dashes everywhere so it's true mapping syntax, and (b) quote scalar values consistently? Otherwise the existing list syntax works fine and I'm inclined to keep it. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants