Dockerfile declare environment variables from file

Viewed 273

Im looking for an elegant way to import env variables to container from a file, trying to avoid hardcoding them in Dockerfile.

#my_file.txt

VAR1=123
VAR2=345
...

I know that this is possible with:

docker run --env-file my_file.txt some_ubuntu_image

but I'm looking for a way to declare this in Dockerfile rather than in run command. Something like:

RUN export -r my_file.txt

or

ENV -r my_file.txt

this ofc does not work, but I hope it gives some image what Im looking for.

1 Answers

I've found a way to do this:

CMD export $(xargs < my_file.txt)

Ofc this may be dangerous workaround, but it works!

Related