1

I have two services in my docker-compose file. Both of them need the same set of environment variables. Is there a better way to do this than duplicating instructions?

PS: I have stored my variables in the ".env" file, which resides in the same directory as the docker-compose file.

example docker-compose file:

version: '3'

services: 
     service_1: 
           build: './s_1/'
           environment: 
                - variable_1 = ${variable_1}
                - variable_2 = ${variable_2}
                - variable_x = ${variable_y}
     service_2:
           build: './s_2/'
           environment: 
                - variable_1 = ${variable_1}
                - variable_2 = ${variable_2}
                - variable_x = ${variable_y}
Hassan Hosseini
  • 410
  • 1
  • 4
  • 20
Swetank Poddar
  • 1,257
  • 9
  • 23
  • 1
    Does this answer your question? [Re-using environmental variables in docker-compose yml](https://stackoverflow.com/questions/36283908/re-using-environmental-variables-in-docker-compose-yml) – Łukasz Ślusarczyk Feb 26 '20 at 19:28
  • @ŁukaszŚlusarczyk, wow. I spend 4 hours looking for an answer before I asked. How did I miss that. That's exactly what i wanted! – Swetank Poddar Feb 26 '20 at 19:31

0 Answers0