title: Docker compose PHP container needs to hit nginx proxy with Host header. How?
body: <p>I have 3 containers. A container that is an nginx reverse proxy:</p>
  
  <pre><code>nginx-proxy:
      image: jwilder/nginx-proxy:latest
      ports:
        - 80:80
        - 443:443
      networks:
        - network
  </code></pre>
  
  <p>Behind that are two php fpm containers on that network. Container A and container B with hostname A and B respectively. I also added these to my local hostsfile:</p>
  
  <pre><code>127.0.0.1 A
  127.0.0.1 B
  </code></pre>
  
  <p>So I can reach from them from my localhost. Both respond to fastCGI requests.</p>
  
  <p>Now I need to do a Guzzle request in A to go to B. This should go via the nginx proxy. How do I add an entry to container A's hostsfile so a request to B will go to <code>nginx-proxy</code> with the header <code>Host: B</code>. But adding</p>
  
  <pre><code>extra_hosts:
      - "B:nginx-proxy"
  </code></pre>
  
  <p>Won't work and I can't find any other way other than hardcoding it which I do not want to do for obvious reasons.</p>
  
  <p>Docker compose file:</p>
  
  <pre><code>  containerA:
      build:
        context: 'docker'
      volumes:
        - .:/var/www/html
        - ./docker/www.conf:/usr/local/etc/php-fpm.d/zz-docker.conf
      networks:
        - network
      environment:
        VIRTUAL_HOST: containerA
        VIRTUAL_ROOT: /var/www/html/public/index.php
        VIRTUAL_PROTO: fastcgi
  
    containerB:
      build:
        context: 'docker'
      volumes:
        - .:/var/www/html
        - ./docker/www.conf:/usr/local/etc/php-fpm.d/zz-docker.conf
      networks:
        - network
      environment:
        VIRTUAL_HOST: containerB
        VIRTUAL_ROOT: /var/www/html/public/index.php
        VIRTUAL_PROTO: fastcgi
  
    nginx-proxy:
      image: jwilder/nginx-proxy:latest
      ports:
        - 80:80
        - 443:443
      volumes:
        - /var/run/docker.sock:/tmp/docker.sock:ro
      networks:
        - network
      environment:
        DEFAULT_HOST: containerA
  
  networks:
    network:
      driver: bridge
  </code></pre>