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

Feature Request: Full Variable Interpolation Support in .env Files (Recursive and Default Values)

Open LordKalEl opened this issue 10 months ago • 3 comments

Is your feature request related to a problem? Please describe.
I'm always frustrated when I cannot use recursive variable substitution in .env files with podman compose. Unlike Docker Compose, podman compose does not support resolving variables defined in terms of other variables within the .env file. For example, defining A=Hello and B=${A} World results in B being interpreted literally as ${A} World instead of Hello World. This forces redundant definitions and violates the DRY principle, making environment configuration error-prone and harder to maintain.

Describe the solution you'd like
podman compose should fully support variable interpolation in .env files, including recursive and default-value syntax (e.g., ${VAR} and ${VAR:-default}), consistent with Docker Compose behavior. This would allow clean, modular configuration where variables can be defined once and reused, improving readability and reducing duplication.

Describe alternatives you've considered
Currently, I work around this by:

  • Using external tools like envsubst or custom shell scripts to pre-process .env files.
  • Duplicating values across the .env file, which increases maintenance effort and risk of inconsistency.
  • Explicitly using interpolation in the compose.yaml (e.g., ENV_VAR: ${ENV_VAR}), which forces changes in the compose file and reduces portability.

These workarounds are non-standard, add complexity, and break compatibility with Docker Compose workflows.

Additional context
This issue is well-documented in the community (e.g., Issue #718, Issue #1064) and represents a deviation from Docker Compose's expected behavior. Supporting full .env interpolation would improve compatibility, usability, and adherence to established container orchestration practices.

LordKalEl avatar Jan 28 '26 05:01 LordKalEl

@Lord-KalEl I created a PR for this, the functionality is there, just wasn't applied to environment variables.

antonpetrov145 avatar Feb 10 '26 04:02 antonpetrov145

I cannot reproduce this issue anymore. Environment:

Debian GNU/Linux 13 (trixie)
Python 3.13.5
podman-compose version 1.6.0
podman version 5.4.2

.env file:

A=Hello
B=${A} World

compose.yml file:

services:
  test:
    image: busybox
    environment:
      A: ${A}
      B: ${B}
      C: ${MISSING:-default}

Running podman-compose config produces the following output:

services:
  test:
    environment:
      A: Hello
      B: Hello World
      C: default
    image: busybox

Variable interpolation in .env files now works correctly, including recursive substitution and default-value syntax (e.g., ${VAR} and ${VAR:-default}), which is consistent with Docker Compose behavior.

This was implemented in #1419.

@p12tic this issue can be closed.

mokibit avatar Jul 15 '26 17:07 mokibit

@mokibit

I can

Aciinema

Gist

Edit: For context, the '${var:+name}' syntax is resolved fine if specified within the docker-compose.yml file directly.

AZMCode avatar Aug 07 '26 00:08 AZMCode