Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share the same environment file with Helm and Docker-Compose

The docker-compose will automatically read the .env file if it resides in a same with the docker-compose.yml directory. With this in mind, I go ahead and in .env file define the app-container environment variable to store the container URL, like so:

app-container=12345.dkr.ecr.us-west-2.amazonaws.com/container-image:v003

In a docker-compose.yml file I then substitute the container URL with the environment variable app-container.

    version: '3'

    services:
      app1:
        build:
          context: .
          dockerfile: my.dockerfile
          image: ${app-container}

It would be great if I could pass the same app-container environment variable to substitute the container's URL defined in Helm's values.yaml file. So, instead of storing the container's URL explicitly

app:
  image: 12345.dkr.ecr.us-west-2.amazonaws.com/container-image:v003

the Helm's values.yaml file could use the same app-container environment variable that was already defined in .env file and used by docker-compose. The Helm's values.yaml file could be then simply defined as:

app:
  image: ${app-container}

I wonder if sharing the same env file between docker-compose and Helm is possible?

like image 743
alphanumeric Avatar asked Nov 18 '25 03:11

alphanumeric


1 Answers

Try this, its little hacky way:

  • First set the environment variable from .env file.
$ cat .env
appcontainer=12345.dkr.ecr.us-west-2.amazonaws.com/container-image:v003
$ while read LINE; do export "$LINE"; done < .env

NOTE: You need to remove - from app-container name. Otherwise you will get this error while setting environment variable bash: export: app-container=12345.dkr.ecr.us-west-2.amazonaws.com/container-image:v003': not a valid identifier

  • Now explicitly set that env in values.yaml using --set option.
helm install --set app.image=$appcontainer ./mychart

But ideally it would be good to have separate env for your docker-compose and helm chart.

Hope this helps.

like image 137
mchawre Avatar answered Nov 20 '25 06:11

mchawre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!