title: docker compose .env variables not set
body: <p>I have the following <code>docker-compose.yml</code>:</p>
  <pre><code>version: &quot;3.9&quot;
  
  services:
    compute:
      build: .
      ports:
        - &quot;27030:27030&quot;
      environment:
        - COMPUTE_HOST=$COMPUTE_HOST
        - COMPUTE_PORT=$COMPUTE_PORT
  </code></pre>
  <p>In my <code>.env</code> file I have the following:</p>
  <pre><code>COMPUTE_HOST=&quot;0.0.0.0&quot;
  COMPUTE_PORT=27030
  </code></pre>
  <p>This is to start up a flask api, but what I get when I run the container with:</p>
  <p><code>docker compose --env-file .env up --build </code></p>
  <p>or</p>
  <p><code>docker-compose --env-file .env up --build</code></p>
  <p>is this:</p>
  <pre><code>apv_compute-compute-1  | APV server starting on port None ...
  apv_compute-compute-1  |  * Serving Flask app 'api' (lazy loading)
  apv_compute-compute-1  |  * Environment: production
  apv_compute-compute-1  |    WARNING: This is a development server. Do not use it in a production deployment.
  apv_compute-compute-1  |    Use a production WSGI server instead.
  apv_compute-compute-1  |  * Debug mode: on
  apv_compute-compute-1  |  * Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
  apv_compute-compute-1  |  * Restarting with stat
  apv_compute-compute-1  |  * Debugger is active!
  apv_compute-compute-1  |  * Debugger PIN: 483-995-326
  </code></pre>
  <p>The api insists on starting on <code>127.0.0.1:5000</code> suggesting that the environment variables are not set at all.</p>
  <p>It also does not work if I change my compose file as follows:</p>
  <pre><code>    environment:
        - COMPUTE_HOST=&quot;0.0.0.0&quot;
        - COMPUTE_PORT=27036
  </code></pre>
  <p>So likely not due to an issue with the .env file.  When running the app outside of docker it works perfectly fine.</p>
  <p>*** UPDATE ***</p>
  <p>The environment variables are actually set inside the container since <code>docker exec image_tag env</code> gives:</p>
  <pre><code>COMPUTE_HOST=0.0.0.0
  COMPUTE_PORT=27030
  </code></pre>
  <p>Also, if I bash into the container, <code>echo $COPMUTE_PORT</code> gives the correct value.</p>
  <p>So this is either <code>dotenv</code> not picking this up or the timing of when these variables are set leading to <code>dotenv</code> not getting them in time.</p>
  <p>I have tried with both <code>load_env</code> and <code>dotenv_values</code>.</p>
  <p><code>Docker version 20.10.14, build a224086</code></p>