Variables in Docker Compose

    15
    5



    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

    Previous articleMake Azure Virtual Desktop Work For You
    Next articleDeploy a Spring Boot App on Kubernetes Cluster | Azure | AKS |Product Engineer | Part-1

    5 COMMENTS

    1. 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!

    2. @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?