title: Docker: How to set environment variables from file during build?
body: <p>I would like to set a list of environment variables as specified in an <code>env.list</code> file during the build process, i.e. have a respective command in the Dockerfile. Like this:</p>
  <pre><code>FROM python:3.9.4-slim-buster
  
  COPY env.list env.list
  
  # Here I need a corresponding command:
  ENV env.list 
  </code></pre>
  <p>The file looks like this:</p>
  <pre><code>FOO=foo
  BAR=bar
  </code></pre>
  <p><strong>My book of already failed attempts / ruled out options:</strong></p>
  <hr />
  <p>On Linux, one can usually set environment variables from a file <code>env.list</code> by running:</p>
  <pre><code>source env.list
  export $(cut -d= -f1 env.list)
  </code></pre>
  <p>However, executing those commands as RUN in the Dockerfile does not work because env variables defined using <code>RUN export FOO=foo</code> are not persisted across different stages of the image.</p>
  <hr />
  <p>I do not want to explicitly set those variables in the Dockerfile using <code>ENV FOO=foo</code> because they contain login credentials. It's also easier to automate/maintain the project if the variables are defined in one place.</p>
  <hr />
  <p>I also don't want to set those variables during <code>docker run --env-file env.list</code> because I need them for a development container which does not &quot;run&quot;.</p>