DEV Community

loading...

Discussion on: Understanding Docker: part 13 – Pass environment variables

Collapse
bugb profile image
bugb

Interesting!! I have bought your two sketch notes before, they are very useful. For this post, I have 2 questions:

  • what software did you use to make this sketch note
  • what happens if I pass an environment with three different value based on 3 ways above (which one should be the last value of the variable)?

And I think you can use this sketch note above for docker-compose, just modify a bit.

Finally it is better if you can share: what should be the recommended way for user!? (For my I prefer declare environments variable to a file)

Collapse
aurelievache profile image
Aurélie Vache Author

Hi
Thanks bugb :)

About the question about the software, I use a samsung tablet with samsung note app, so I sketch with a pencil myself :).

About the question "what happens if I pass an environment with three different value based on 3 ways above (which one should be the last value of the variable)?":

I tested it and here the result:

$ cat myfile.env
ENV=int2

$ docker run --env-file=myfile.env mygolang:test
hello
ENV=int2

$ docker run -e ENV="int1" --env-file=myfile.env mygolang:test
ENV=int1

$ docker run --env-file=myfile.env -e ENV="int1" mygolang:test
hello
ENV=int1

--> if you pass environment variables through -e and --env-file, then finally the env value is passed through -e, but not the one in env-file ;)

The recommended way for the user, as usually: it depends!
You can pass environment values through your CI/CD toolchain for example, in your job you can add parameter and pass the region and/or the environment to the docker run command.

Or an environment file can be create and pass depending on the target environment.

It really depends on the context of your team, your project... :)

Collapse
aurelievache profile image
Aurélie Vache Author

And I added a third page of this sketchnotes thanks to your remark 😀