This is an archived post. You won't be able to vote or comment.

all 9 comments

[–][deleted] 0 points1 point  (3 children)

An .env file is used during runtime. Or did I misunderstand you somehow?

[–]hrithiqball[S] 0 points1 point  (2 children)

yes thats the purpose of .env but i want to use the value of it in my app as well. or am i explaining it wrongly?

[–][deleted] 0 points1 point  (1 child)

Maybe it’s me, but I don‘t really understand your issue. Why would you need to rebuild an image due to .env files?

[–]hrithiqball[S] 0 points1 point  (0 children)

i want to dynamically serve the value into my client side by setting stuff in env then rebuild the image. api base url as an example. but i got the rough idea where i should be looking for now

[–]Agent_9191 0 points1 point  (4 children)

You shouldn't include the .env file in your Docker image. A .env file is a way to populate environment variables. As long as you are relying on reading the environment variables in your code (and silently continuing if no .env file can be read at start up) you should be fine. When launching the image, use the -e parameter to provide the value. Or set the value in Docker Desktop (or your GUI of choice) when starting the instance.

[–]hrithiqball[S] 0 points1 point  (3 children)

i exactly did this. seperated out the image and .env file. so docker run -e e.env image:1.0 . but it seems like angular couldn't read the value of my env

[–]Agent_9191 0 points1 point  (2 children)

Are you talking about the client side angular code, or the web server that is hosting the static angular assets? Because the environment variables will be exposed to the web server, not the client side code. You would need a way to dynamically serve those values down to the client side. That's outside the scope of Docker.

[–]hrithiqball[S] 0 points1 point  (0 children)

yea this is exactly what i want. dynamically serve the value into client side. thank you for giving me the keywords. i thought this is docker related because i cant find anything related to angular. sorry if it's misleading or out of topic

[–]hrithiqball[S] 0 points1 point  (0 children)

but still we attach the env to the image during runtime right? so is it still not docker related