title: env file-named volume in docker-compose
body: <p>I'm new to Docker. I am writing a docker-compose file which creates 2 containers, <em>foo</em> and <em>bar</em>, sharing a volume <em>data</em>:</p>
  
  <pre><code>services:
  
      foo:
          container_name: foo
          build: ./foo
          volumes:
              - data:/var/lib/
  
      bar:
          container_name: bar
          build: ./bar
          volumes:
              - data:/var/lib/
          depends_on:
              - foo
  
  volumes:
      data:
  </code></pre>
  
  <p>Now, I want to use the environment variable <em>TAG</em>, to tag containers and volumes, in order to specify if it's for <em>test</em> or <em>production</em>. I expects something like this:</p>
  
  <pre><code>services:
  
      foo:
          container_name: foo_${TAG}
          build: ./foo
          volumes:
              - data_${TAG}:/var/lib/
  
      bar:
          container_name: bar_${TAG}
          build: ./bar
          volumes:
              - data_${TAG}:/var/lib/
          depends_on:
              - foo
  
  volumes:
      data_${TAG}:
  </code></pre>
  
  <p>Obviously, docker-compose is unhappy because of the last line containing <code>data_${TAG}:</code>.</p>
  
  <p>How can I name my volume with <em>TAG</em> env variable?</p>