Writeup Here: https://serversforhackers.com/c/div-variables-in-docker-compose
We can use variables in our docker-compose.yml files!
Book: https://book.serversforhackers.com/
Deploy: https://deploy.serversforhackers.com/
Docker: https://shippingdocker.com/
Laravel: https://scalinglaravel.com
Twitter: https://twitter.com/fideloper
Facebook: https://www.facebook.com/serversforhackers/
source
I am stoked, this looked like exactly what i needed but it doesn't seem to be working for me. I have a JOB_TOKEN that i do not want anyone on my team to accidentally push to github. I've tried export JOB_TOKEN = abcde and putting it under environment: – ${JOB_TOKEN} in order to have that ready for the Dockerfile I'm working with. Changing ports to ${APP_PORT} like your example works but not for environmental variables. Is there no good way to pass an environment value from the host or another file into docker-compose or a Dockerfile? I also placed it in an .env file but it doesn't seem to work either. What am i missing? All the solutions online seem to work with Swarm but not Compose. FYI, I'm pretty new at docker but i've done a lot already. This is the last piece of the puzzle i need for my POC, any tips? Thanks!
Thank you for tutorials. What is the terminal are you using? š
@0:17, "ports" variable is defined. There is a dash "-" in front of 80:80. However, I have seen docker compose files that declare variables without the dash in front. Same goes for "volumes" variable…
Is dash necessary in compose? Is there a difference in requirement for the dash between compose Version 2.x and 3.x?
Extension to this "dash" question.
In your "environment" variable section, there is no dash in front of MYSQL_ROOT_PASSWORD, …
So, does it mean that "dash" should not be use in "environment"?
Also, if there are multiple entries for a variable, say "volumes", should we start each line (e.g. in your – cachedata:/data) with a dash up front?
Good tutorial, but I have a question, Why in my Linux a .env created file is not saved in the folder? It's as if it dissapeared or is hidden, I couldn't find that anymore. Can you tell me why?
Thanks for all, liked and subscribed
Thank you.
On windows you can SET an environment variable which matches the name in the compose file. Docker will complain if you attempt to set it as a prefix to the docker-compose command.