containers / podman-compose

a script to run docker-compose.yml using podman
GNU General Public License v2.0
4.97k stars 475 forks source link

Replicate environment variable from local environment fails with default `.env` -file #1011

Open hmontone opened 1 month ago

hmontone commented 1 month ago

Describe the bug If environment variable value is defined in default .env -file and environment variable is replicated in compose.yml file, environment variable is not passed to container

To Reproduce .env:

TEST=test

compose.yml:

services:
  test:
    image: busybox
    environment:
      - TEST
    command: printenv

Expected behavior Environment variable TEST should be included in output

Actual behavior Environment variable TEST is not included in output

Output

$ podman compose run --rm test
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
container=podman
TERM=xterm
HOME=/root
HOSTNAME=aa7b6faaf810

My environment:

$ podman compose run --rm test
container=podman
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOME=/root
HOSTNAME=6da914b12a2e
$ podman compose version
podman-compose version 1.2.0
podman version 5.1.2
$ cat /etc/os-release
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://gitlab.archlinux.org/groups/archlinux/-/issues"
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=archlinux-logo
$ pacman -Qi podman podman-compose
Name            : podman
Version         : 5.1.2-1
Description     : Tool and library for running OCI-based containers in pods
Architecture    : x86_64
URL             : https://github.com/containers/podman
Licenses        : Apache-2.0
Groups          : None
Provides        : None
Depends On      : catatonit  conmon  containers-common  oci-runtime  gcc-libs  glibc  iptables  device-mapper  libdevmapper.so  gpgme  libgpgme.so=11-64  libseccomp
                  libseccomp.so=2-64  passt
Optional Deps   : apparmor: for AppArmor support
                  btrfs-progs: support btrfs backend devices
                  cni-plugins: for an alternative container-network-stack implementation
                  fuse-overlayfs: for storage driver in rootless environment
                  slirp4netns: for alternative rootless network support
                  podman-compose: for docker-compose compatibility [installed]
                  podman-docker: for Docker-compatible CLI [installed]
Required By     : podman-compose  podman-docker
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 77.29 MiB
Packager        : David Runge <dvzrv@archlinux.org>
Build Date      : Fri 12 Jul 2024 12:26:12 AM EEST
Install Date    : Sat 13 Jul 2024 07:33:05 PM EEST
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : Signature

Name            : podman-compose
Version         : 1.2.0-1
Description     : A script to run docker-compose.yml using podman
Architecture    : any
URL             : https://github.com/containers/podman-compose
Licenses        : GPL-2.0-only
Groups          : None
Provides        : None
Depends On      : podman  python  python-dotenv  python-yaml
Optional Deps   : aardvark-dns: resolve hostnames of linked containers [installed]
Required By     : None
Optional For    : podman
Conflicts With  : None
Replaces        : None
Installed Size  : 486.06 KiB
Packager        : David Runge <dvzrv@archlinux.org>
Build Date      : Fri 05 Jul 2024 11:00:08 AM EEST
Install Date    : Thu 11 Jul 2024 09:50:35 AM EEST
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : Signature
hmontone commented 1 month ago

Behaviour in Docker Compose (as described in documentation) is what I expected.

hmontone commented 1 month ago

It seems that if I interpolate value in compose.yml it picks the value correctly from .env:

$ cat .env
TEST=test
$ cat compose.yml
services:
  test:
    image: busybox
    environment:
      - TEST=$TEST
    command: printenv
$ podman compose run --rm test
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
container=podman
TERM=xterm
TEST=test
HOME=/root
HOSTNAME=cb5574ddcaef

On the other hand if I set environment variable as local environment variable then it is replicated correctly:

$ cat .env
TEST=test
$ cat compose.yml
services:
  test:
    image: busybox
    environment:
      - TEST
    command: printenv
$ TEST=local podman compose run --rm test
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
container=podman
TERM=xterm
TEST=local
HOME=/root
HOSTNAME=481b5794f566
legobeat commented 1 month ago

Might be the same issue as:

Related: