1

I've read this, this and this.

Despite that this is asked many times, I don't understand it, and it seems inconclusive. Please consider before posting possible duplicates.

On my Ubuntu 16, I have a container that has to access services outside the container. It is not possible to use --network="host", because that is against the purpose of using Docker for me. Plus, the documentation says: "Bridge networks are usually used when your applications run in standalone containers that need to communicate", which is this case.

So by choosing the bridge network approach, I have tried the solution here (By far the most popular Q&A found online). Where it says use the "route" command inside the container to get the Host IP:

export DOCKER_HOST_IP=$(route -n | awk '/UG[ \t]/{print $2}')

There are two issues:

1: Is this the most straight forward solution to such a trivial need?

2: I execute this in my container in my node application:

 await execSync("route -n | awk '/UG[ \t]/{print $2}'", (err, stdout,stderr) =>{
        if (err) {
            console.error("Failed: " + err);
            return;
        }
        if (stdout)
            console.log(stdout);
        if (stderr)
            console.error(stderr);
    });

Which (as expected) results in this:

/bin/sh: 1: route: not found

I tried the --add-host solution, But how do i know what IP Number to use? In other words, where does this IP come from?

--add-host=testing.example.com:10.0.0.1
Makan
  • 2,508
  • 4
  • 24
  • 39
  • The purpose of bridges is to communicate containers, not containers with their host. So I'm not sure if it fits your case. – pacuna Sep 12 '18 at 03:56
  • thanks for the comment, But, a bridge implements quite a handful share of the network stack. Therefore it can open connections to ANYwhere (`testing.example.com` ) I don't see how only the host can be excluded from this. – Makan Sep 12 '18 at 08:32

0 Answers0