Search code examples
dockerdocker-composedocker-swarm

what is the recommended way of passing environment variables to a docker service


I am using compose version 3 to start multiple services. Each service has a bunch of environment variables that need to be passed to the containers. What is the recommended way to do it?


Solution

  • Environment directive should be used when either there is only one service or multiple services with different environment variables. If there are multiple services using common variables, then env_file should is a much cleaner approach.