Skip to content

[BUG] config --no-interpolate ineffective in a corner case #11547

Closed as not planned

Description

@luciangabor

Description

Please see the steps below

Steps To Reproduce

  1. Create the compose.yaml
services:
  service:
    network_mode: none
    image: bash
    entrypoint:
      - bash
      - -vc
    command:
      - echo "FOO:$${FOO:-default}, BAR:$${BAR:-default}"
    environment:
      FOO: ${FOO:-}
      BAR:
  1. Experiment with setting or not the two variables
$ docker compose config --no-interpolate
name: interpolate
services:
  service:
    command:
      - echo "FOO:$${FOO:-default}, BAR:$${BAR:-default}"
    entrypoint:
      - bash
      - -vc
    environment:
      BAR: null
      FOO: ${FOO:-}
    image: bash
    network_mode: none

$ env FOO=FOO BAR=BAR docker compose config --no-interpolate
name: interpolate
services:
  service:
    command:
      - echo "FOO:$${FOO:-default}, BAR:$${BAR:-default}"
    entrypoint:
      - bash
      - -vc
    environment:
      BAR: BAR
      FOO: ${FOO:-}
    image: bash
    network_mode: none

Observe that BAR is "interpolated" despite the flag, while both ways to pass a homonym variables work more or less the same:

$ docker compose --progress none up --no-log-prefix 
Attaching to service-1
echo "FOO:${FOO:-default}, BAR:${BAR:-default}"
FOO:default, BAR:default
service-1 exited with code 0

$ env FOO=FOO BAR=BAR docker compose --progress none up --no-log-prefix 
Attaching to service-1
echo "FOO:${FOO:-default}, BAR:${BAR:-default}"
FOO:FOO, BAR:BAR
service-1 exited with code 0

Compose Version

Docker Compose version v2.24.6

Docker Environment

No response

Anything else?

No response

Activity

  1. 1arp commented on Feb 28, 2024

    @1arp
    Contributor
  2. luciangabor commented on Feb 28, 2024

    @luciangabor
    Author

    Maybe here's the issue:

    content = escapeDollarSign(content)

    And that breaks other cases too - like when a variable is used to point to an included/extended file ...

  3. ndeloof commented on Feb 28, 2024

    @ndeloof
    Contributor

    This is not interpolation. When you set BAR without a value, you ask compose to just propagate your environment to container, which he did. interpolation is about replacing variables in your compose.yaml file

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions