Skip to content

Variable declaration on the first line of .env ignored #1357

@rcotta

Description

@rcotta

Describe the bug

When using a .env file with podman-compose, environment variables defined on the first line of the file are not expanded in docker-compose.yml.
If a dummy first line (comment or another variable declaration) is added, the variables are expanded correctly.

IMPORTANT: if you try reproduce the steps below but, this time, adding a dummy first line to the .env file, then it behaves as expected.

Steps to reproduce the behavior:

  1. Create a .env file with the following contents:
VAR1=value1
VAR2=value2
  1. Create a docker-compose.yml with the following contents:
services:

  my-service:
    image: mongo:6.0
    args:
      - arg1=${VAR1}
      - arg2=${VAR2}
    restart: unless-stopped
  1. run podman-compose config

Expected behavior
VAR1 value should be expanded.

Actual behavior

VAR1 is not expanded.

Output

services:
  my-service:
    args:
    - arg1=
    - arg2=value2
    image: mongo:6.0
    restart: unless-stopped
$ podman-compose version
podman-compose version 1.5.0
podman version 5.5.2

$ podman version
Client:       Podman Engine
Version:      5.5.2
API Version:  5.5.2
Go Version:   go1.24.4
Git Commit:   e7d8226745ba07a64b7176a7f128e4ef53225a0e
Built:        Tue Jun 24 13:13:04 2025
OS/Arch:      windows/amd64

Server:       Podman Engine
Version:      5.6.1
API Version:  5.6.1
Go Version:   go1.24.6
Git Commit:   1e2b2315150b2ffa0971596fb5da8cd83f3ce0e1
Built:        Wed Sep  3 21:00:00 2025
OS/Arch:      linux/amd64
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions