title: How to set up a bridge between two docker containers (connection refused)
body: <p>Well I'm trying to set up a bridge between a static file (nginx) server and a dynamic content server.</p>
  
  <p>Both dockers work correctly as a singular entity. However it seems the nginx server can't forward (reverse proxy) data to the dynamic content server.<br>
  It also works perfectly fine if I do not use dockers, but instead just run in the host operating system.</p>
  
  <p>The dockers (containers named "sails" and "nginx") are connected with:</p>
  
  <pre><code>docker network create -d bridge --subnet 172.25.0.0/16 bink
  docker network connect bink sails
  docker network connect bink nginx
  </code></pre>
  
  <p>The nginx tries has a link to a proxy given by:</p>
  
  <pre><code>location /api {
      proxy_pass  http://127.0.0.1:1337;
  }
  </code></pre>
  
  <p>This is the port the other docker listens to:   <code>http://127.0.0.1:1337/api/get-employees/</code> (example url) does give me correct data, when ran from the host os. (And when the docker is alive).</p>
  
  <p>However <code>error.log</code> in the nginx server shows:</p>
  
  <blockquote>
    <p>2018/03/22 15:21:12 [error] 8#8: *11 connect() failed (111: Connection
    refused) while connecting to upstream, client: 172.25.0.1, server: _,
    request: "GET /api/order-status-list/?_dc=1521732072867 HTTP/1.</p>
  </blockquote>
  
  <p>I've also tried manually getting the data inside the nginx server (after <code>docker exec -it nginx sh</code>)</p>
  
  <pre><code>wget 127.0.0.1:1337/api/get-employees
  wget: can't connect to remote host (127.0.0.1): Connection refused
  </code></pre>
  
  <hr>
  
  <p>Results of <code>docker network inspect bink</code></p>
  
  <pre><code>[
      {
          "Name": "bink",
          "Id": "e859514bd4186a0cc7fa7b1021c05e99cbb1d6fcf903b024c63fad2c5880ec6a",
          "Created": "2018-03-22T16:06:58.373431562+01:00",
          "Scope": "local",
          "Driver": "bridge",
          "EnableIPv6": false,
          "IPAM": {
              "Driver": "default",
              "Options": {},
              "Config": [
                  {
                      "Subnet": "172.25.0.0/16"
                  }
              ]
          },
          "Internal": false,
          "Attachable": false,
          "Ingress": false,
          "ConfigFrom": {
              "Network": ""
          },
          "ConfigOnly": false,
          "Containers": {
              "1d96ac9b62dcce80d24552b8c9513e4d91f9c9fb6bc9ac731d2e635ba1ad0ac4": {
                  "Name": "nginx",
                  "EndpointID": "0429077af2cf0573ec073e9834fae7b710daf3c9d4e0f9bce7638ad9c4d07205",
                  "MacAddress": "02:42:ac:19:00:03",
                  "IPv4Address": "172.25.0.3/16",
                  "IPv6Address": ""
              },
              "2ce6e54bf01c73ca06306b49a8021ab2b438710607a96a32f3c3349d89e93293": {
                  "Name": "sails",
                  "EndpointID": "98c5bece45cd77a468a8dc92c6938525bd8ef38d27051e675ae1c4494e5081b4",
                  "MacAddress": "02:42:ac:19:00:02",
                  "IPv4Address": "172.25.0.2/16",
                  "IPv6Address": ""
              }
          },
          "Options": {},
          "Labels": {}
      }
  ]
  </code></pre>
  
  <p>everything seems to be as expected?</p>
  
  <hr>
  
  <p>EDIT: I can get data from the sails/dynamic from the nginx docker by explicitly stating the ip adress of the sails docker:</p>
  
  <pre><code>wget 172.25.0.2:1337/api/get-employees
  </code></pre>
  
  <p>gives expected results. However this is not a solution as the internal ips of the docker networks should be a implementation detail and should not be used.</p>