title: Access outside port from docker container
body: <p>I've read <a href="https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach/24326540#24326540">this</a>, <a href="https://blog.codeship.com/using-the-add-host-flag-for-dns-mapping-within-docker-containers/" rel="nofollow noreferrer">this</a> and <a href="https://stackoverflow.com/questions/48458862/access-service-on-host-machine-from-docker-container">this</a>.</p>
  
  <p>Despite that this is asked many times, I don't understand it, and it seems inconclusive. Please consider before posting <em>possible duplicates</em>.</p>
  
  <p>On my Ubuntu 16, I have a container that has to access services outside the container. It is not possible to use <code>--network="host"</code>, because that is against the purpose of using Docker for me. Plus, <a href="https://docs.docker.com/network/#network-drivers" rel="nofollow noreferrer">the documentation</a> says: "Bridge networks are usually used when your applications run in standalone containers that need to communicate", which is this case.</p>
  
  <p>So by choosing the <code>bridge</code> network approach, I have tried the solution <a href="https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach/24326540#24326540">here</a> (By far the most popular Q&amp;A found online). Where it says use the "route" command inside the container to get the Host IP:</p>
  
  <pre><code>export DOCKER_HOST_IP=$(route -n | awk '/UG[ \t]/{print $2}')
  </code></pre>
  
  <p>There are two issues:</p>
  
  <p>1: Is this the most straight forward solution to such a trivial need?</p>
  
  <p>2: I execute this in my container in my node application:</p>
  
  <pre><code> await execSync("route -n | awk '/UG[ \t]/{print $2}'", (err, stdout,stderr) =&gt;{
          if (err) {
              console.error("Failed: " + err);
              return;
          }
          if (stdout)
              console.log(stdout);
          if (stderr)
              console.error(stderr);
      });
  </code></pre>
  
  <p>Which (as expected) results in this: </p>
  
  <pre><code>/bin/sh: 1: route: not found
  </code></pre>
  
  <p>I tried the <a href="https://blog.codeship.com/using-the-add-host-flag-for-dns-mapping-within-docker-containers/" rel="nofollow noreferrer">--add-host solution</a>, But how do i know what IP Number to use?
  In other words, where does this IP come from?</p>
  
  <pre><code>--add-host=testing.example.com:10.0.0.1
  </code></pre>