title: Calling an API in a Docker container from a different Docker container (same host, Apache)
body: <p>Situation:</p>
  
  <p>I have 2 docker containers running both Symfony 4 applications. cte_app and cte_fe. cte_app is exposed to port 8080 on the host and cte_fe to port 80.</p>
  
  <p>cte_app contains API methods which I need to consume with cte_fe. I can consume the API from cte_app on the host machine just fine (using Postman) but not via cte_fe in a PHP function using cURL, I get a connection refused error (using localhost:8080 and container-name (which is dependant)). When I use the Docker's gateway address I can consume the API from the cte_fe container just fine. But I can't guarantee that the gateway address won't change over time.</p>
  
  <p>What is the preferred way to call an API endpoint between 2 containers living on the same host? Is there some flag I have missed in the documentation which exposes the gateway address to the container as an environment variable? </p>
  
  <pre><code>version: '3'
  services:
  
  cte_db:
      image: mysql:5.7.24
      restart: on-failure
      container_name: cte_db
      ports:
        - "3306:3306"
      volumes:
        - /cte_data/mysql:/var/lib/mysql
      environment:
          MYSQL_ROOT_PASSWORD: somepassword
          MYSQL_DATABASE: somedatabase
          MYSQL_USER: someuser
          MYSQL_PASSWORD: somepassword
  
  cte_apache:
      build: .docker/apache
      container_name: cte_apache
      ports:
         - 8080:8080
         - 80:80
      volumes:
         - .docker/config/vhosts:/etc/apache2/sites-enabled
         - ./cte_app:/home/wwwroot/cte_app
         - ./cte_fe:/home/wwwroot/cte_fe
      depends_on:
         - cte_fe
         - cte_app
  
  cte_app:
      build: .docker/php
      container_name: cte_app
      volumes:
         - ./cte_app:/home/wwwroot/cte_app
      depends_on:
         - cte_db
  
  cte_fe:
      build: .docker/php
      container_name: cte_fe
      volumes:
        - ./cte_fe:/home/wwwroot/cte_fe
      depends_on:
        - cte_app
        - cte_db
  </code></pre>