title: Docker nginx-proxy : proxy between containers
body: <p>I am currently running a development stack using Docker-Compose in my company, to provide to developers everything they need to code our applications.</p>
  
  <p>It includes in particular:</p>
  
  <ul>
  <li>a Gitlab container (<a href="https://github.com/sameersbn/docker-gitlab" rel="nofollow">sameersbn/gitlab</a>) to manage private GIT repositories,</li>
  <li>a Jenkins container (<a href="https://hub.docker.com/_/jenkins/" rel="nofollow">library/jenkins</a>) for building and continuous integration,</li>
  <li>an Archiva container (<a href="https://hub.docker.com/r/ninjaben/archiva-docker/" rel="nofollow">ninjaben/archiva-docker</a>) to manage Maven repositories.</li>
  </ul>
  
  <p>In order to secure the services through HTTPS, and exposing them to the outside world, I installed the excellent nginx-proxy container (<a href="https://github.com/jwilder/nginx-proxy" rel="nofollow">jwilder/nginx-proxy</a>) which allows automated nginx proxy configuration using environment variables on containers, and automated HTTP to HTTPS redirection.</p>
  
  <p>DNS are configured to map each public URL of dockerized services to the IP of the host.</p>
  
  <p>Finally, using Docker-Compose, my docker-compose.yml file looks like this :</p>
  
  <pre><code>version: '2'
  services:
    nginx-proxy:
      image: jwilder/nginx-proxy
      ports:
      - "80:80"
      - "443:443"
      volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - /var/config/nginx-proxy/certs:/etc/nginx/certs:ro
    postgresql:
      # Configuration of postgresql container ...
    gitlab:
      image: sameersbn/gitlab
      ports:
      - "10022:22"
      volumes:
      - /var/data/gitlab:/home/git/data
      environment:
      # Bunch of environment variables ...
      - VIRTUAL_HOST=gitlab.my-domain.com
      - VIRTUAL_PORT=80
      - CERT_NAME=star.my-domain.com
    archiva:
      image: ninjaben/archiva-docker
      volumes:
      - /var/data/archiva:/var/archiva
      environment:
      - VIRTUAL_HOST=archiva.my-domain.com
      - VIRTUAL_PORT=8080
      - CERT_NAME=star.my-domain.com
    jenkins:
      image: jenkins
      volumes:
      - /var/data/jenkins:/var/jenkins_home
      environment:
      - VIRTUAL_HOST=jenkins.my-domain.com
      - VIRTUAL_PORT=8080
      - CERT_NAME=star.my-domain.com
  </code></pre>
  
  <p>For a developer workstation, everything works as expected. One can access the difference services through <code>https://gitlab.my-domain.com</code>, <code>https://repo.my-domain.com</code> and <code>https://jenkins.my-domain.com</code>.</p>
  
  <p>The problem occurs when one of the dockerized service access another dockerized service. For instance, If I try to access <code>https://archiva.my-domain.com</code> from jenkins docker, I will get a timeout error from the proxy.</p>
  
  <p>It seems that even if <code>archiva.my-domain.com</code> is resolved as the public host IP from the docker container, <strong>requests coming from dockerized services are not proxied by nginx-proxy.</strong></p>
  
  <p>As far as I understood, docker-nginx is handling requests coming from the host network, but does not care about the ones coming from the internal container network (_dockerconfig_default_ for a Docker-Compose stack).</p>
  
  <p>You could say, why would I need to use the proxy from a container ? Of course, I could use URL <code>http://archiva:8080</code> from Jenkins container, and it would work. But this kind of configuration is not scalable.</p>
  
  <p>For example, using a Gradle build to compile one application, the build.gradle needs to declare my private repository through <code>https://archiva.my-domain.com</code>. It will work if build is launched from a developer workstation, but not through the jenkins container ...</p>
  
  <p>Another example is an authentication in Jenkins by OAuth GitLab service, where the same URL GitLab authentication needs to be <strong>both</strong> available from the outside, and inside the Jenkins container.</p>
  
  <p>My question here is then : <strong>How to configure nginx-proxy to proxy a request from a container to another container ?</strong></p>
  
  <p>I did not see any topic discussing this problem, and I do not understand enough the problem to build a solution on nginx configuration.</p>
  
  <p>Any help would be really appreciated.</p>