podman-compose icon indicating copy to clipboard operation
podman-compose copied to clipboard

Environment Variables values are not interpolated

Open achdmbp opened this issue 11 months ago • 3 comments

Description:

When specifying an environment variable under the services environment section with interpolation (e.g., MYENV=${DEBUG-1}), the container is created with MYENV set to the literal value "${DEBUG-1}" instead of 1 when the DEBUG environment variable is not set.

Steps to Reproduce:

  1. Define a service in your docker-compose.yml file with an environment variable that uses interpolation:
    services:
      myservice:
        environment:
          - MYENV=${DEBUG-1}
    
  2. Ensure the DEBUG environment variable is not set in your shell.
  3. Run podman-compose up.

Expected Behavior:

The container should be created with MYENV set to 1 when the DEBUG environment variable is not set.

Actual Behavior:

The container is created with MYENV set to the literal value "${DEBUG-1}".

Additional Information:

  • podman-compose version: 1.3.0
  • podman version: 5.2.2
  • Operating System: Linux workspaced50dd4e90744453d-574f885c55-d4494 5.14.0-284.96.1.el9_2.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 29 13:37:02 EST 2024 x86_64 x86_64 x86_64 GNU/Linux

achdmbp avatar Jan 21 '25 20:01 achdmbp

Facing the same issue. But a bit different:

Works, prints ¨1¨ when DEBUG env var is not defined on host:

services:
  test:
    container_name: test
    image: docker.io/debian
    command: env
    environment:
      - MYENV=${DEBUG:-1}

Does not work, prints ¨${MYENV:-1}¨:

services:
  test:
    container_name: test
    image: docker.io/debian
    command: env
    environment:
      - MYENV=${MYENV:-1}

Seems to be something circular?

koen-serneels avatar Jan 23 '25 07:01 koen-serneels

Just tested a similar use-case, it is (was) working in 1.2.0, I can't really tell which MR brought the regression.

I'll be using pip install podman-compose==v1.2.0 for now

tales-aparecida avatar Apr 17 '25 20:04 tales-aparecida

I just ran into the same problem, exactly with providing a default for a variable that's supposed to be configurable, so the definition is circular, like:

environment:
  MYENV: '${MYENV:-default value}'

If the variable to set and the referenced variable have different names it works fine.

airtower-luna avatar Aug 06 '25 12:08 airtower-luna