title: Dockerfile: how to set env variable from file contents
body: <p>I want to set an environment variable in my Dockerfile.  </p>
  
  <p>I've got a <code>.env</code> file that looks like this:
  <code>FOO=bar</code>.  </p>
  
  <p>Inside my Dockerfile, I've got a command that parses the contents of that file and assigns it to FOO.</p>
  
  <p><code>RUN 'export FOO=$(echo "$(cut -d'=' -f2 &lt;&lt;&lt; $(grep FOO .env))")'</code></p>
  
  <p>The problem I'm running into is that the script above doesn't return what I need it to. In fact, it doesn't return anything.</p>
  
  <p>When I run <code>docker-compose up --build</code>, it fails with this error.</p>
  
  <p><code>The command '/bin/sh -c 'export FOO=$(echo "$(cut -d'=' -f2 &lt;&lt;&lt; $(grep FOO .env))")'' returned a non-zero code: 127</code></p>
  
  <p>I know that the command <code>/bin/sh -c 'echo "$(cut -d'=' -f2 &lt;&lt;&lt; $(grep FOO .env))"'</code> will generate the correct output, but I can't figure out how to assign that output to an environment variable.</p>
  
  <p>Any suggestions on what I'm doing wrong?</p>