Body: <p>Is it possible to substitute (without the use of external tools like <code>envsubst</code>) values in an environment file used in docker-compose (using <code>env_file</code>) with values on a <code>.env</code> file in the folder?</p>
  <p>Say I have this <code>.env</code> file:</p>
  <pre><code>REGISTRY=something
  TAG=something-else
  </code></pre>
  <p>Now in my <code>docker-compose.yml</code> I can have:</p>
  <pre class="lang-yaml prettyprint-override"><code># ...
     my_service:
        environment:
          - USE_IMAGE:${REGISTRY}/my_image:${TAG}
  # ...
  </code></pre>
  <p>What I'd like is having a different environment file (say, <code>myservice.env</code>), like this:</p>
  <pre><code>USE_IMAGE=${REGISTRY}/my_image:${TAG}
  </code></pre>
  <p>And use it on the compose file like:</p>
  <pre class="lang-yaml prettyprint-override"><code># ...
     my_service:
        env_file:
          - myservice.env
  # ...
  </code></pre>
  <p>However by default, docker-compose (which is the one reading the .env file) doesn't seem to be substituting anything on the other files and I get the literal value.</p>
  <p>Is there a way to do this without requiring to have a &quot;rendered&quot; file, directly with docker compose?</p>
  <p>I understand I could make a script to pre-process those files using <code>envsubst</code> or something similar, but I'm trying to find a solution without that</p>
  
Comments: CC BY-SA 4.0
Comments: 2021-01-16T02:36:43.923Z
Comments: Your myservice.env file must be in the format of KEY=VALUE.  That still may not give you what you want, https://stackoverflow.com/q/37926473/8254477 is an alternative pattern that works quite well.
Comments: swysocki
Comments: CC BY-SA 4.0
Comments: 2021-01-16T06:22:15.437Z
Comments: @swysocki oh yes, sorry, that was a typo... corrected. I'll check your link, thanks
Comments: Jcl
Tags: <docker-compose><environment-variables>
Title: Substitute env_file values with .env values on docker compose
UserDisplayName: Jcl
ThreadText: # Substitute env_file values with .env values on docker compose
  
  (Asked by: username_0 on 2021-01-14)
  
  Is it possible to substitute (without the use of external tools like `envsubst`) values in an environment file used in docker-compose (using `env_file`) with values on a `.env` file in the folder?
  
  Say I have this `.env` file:
  
  ```
  REGISTRY=something
  TAG=something-else
  
  ```
  
  Now in my `docker-compose.yml` I can have:
  
  ```yaml
  # ...
     my_service:
        environment:
          - USE_IMAGE:${REGISTRY}/my_image:${TAG}
  # ...
  
  ```
  
  What I'd like is having a different environment file (say, `myservice.env`), like this:
  
  ```
  USE_IMAGE=${REGISTRY}/my_image:${TAG}
  
  ```
  
  And use it on the compose file like:
  
  ```yaml
  # ...
     my_service:
        env_file:
          - myservice.env
  # ...
  
  ```
  
  However by default, docker-compose (which is the one reading the .env file) doesn't seem to be substituting anything on the other files and I get the literal value.
  
  Is there a way to do this without requiring to have a "rendered" file, directly with docker compose?
  
  I understand I could make a script to pre-process those files using `envsubst` or something similar, but I'm trying to find a solution without that
  
  **Tags:** docker-compose, environment-variables
  
  > **Comments:**
  > **username_1**: Your myservice.env file must be in the format of KEY=VALUE.  That still may not give you what you want, https://stackoverflow.com/q/37926473/8254477 is an alternative pattern that works quite well.  
  > **username_0**: @username_1 oh yes, sorry, that was a typo... corrected. I'll check your link, thanks  
  
  ---
  
  ## 0 answers
  
  