Set extra host in environment variables
<p>I'm using docker compose to run my application. And for do that I need to set the hosts inside container (it's depends on the environment i'm running).</p>

<p>My approach was:</p>

<p>Create an environment file and set the variable:</p>

<pre><code>#application.env
SERVER_IP=10.10.9.134
</code></pre>

<p>My docker compose file looks like:</p>

<pre><code>version: '2'
services:

  api:
    container_name: myApplication
    env_file:
      - application.env
    build: ./myApplication/
    entrypoint: ./docker/api-startup.sh
    ports:
      - "8080:8080"
    depends_on:
      - redis    
    extra_hosts: &amp;extra_hosts
      myip: $SERVER_IP
</code></pre>

<p>But my problem is that the variable SERVER_IP is never replaced. </p>

<p>When I run docker-compose config I see:</p>

<pre><code>services:
  api:
    build:
      context: /...../myApplication
    container_name: myApplication
    depends_on:
    - redis
    entrypoint: ./docker/api-startup.sh
    environment:
      SERVER_IP: 10.10.9.134
    extra_hosts:
      myip: ''
    ports:
    - 8080:8080
</code></pre>

<p>I've tried to replace the variable reference using $SERVER_IP or ${SERVER_IP} but it didn't work.</p>