0

I created a new network. Exposed port 8086 for one of my containers and also published this port. Run both containers with --network influx-net.

Check docker network inspect influx-net gives my

docker network inspect influx-net
[
    {
        "Name": "influx-net",
        "Id": "76ad2f3ec76e15d88330739c2b3db866a15d5affb0912c64c7ec7615b14e8570",
        "Created": "2021-11-09T17:32:42.479637982+09:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "92c0f2c5dc5c75db15e5a5ea0bed6ec5047f0c57dba06283ef6e72c8adcc6a3a": {
                "Name": "ultimate_hydroponics",
                "EndpointID": "529c2c31baaec7685251a584e8f5643b4669966372b629d67f3a9910da5e809c",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            },
            "a678409dbc43685fd089ed29f42601b67c46c20b66c277e461a8fe2adad31b5a": {
                "Name": "influxdb",
                "EndpointID": "73263b9969dc9c67760ec3aab4ebab75e16763c75cd498828a737d9e56ed34ef",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

So my both containers are connected to the network influx-net. But when I trying to ping or wget InfluxDB container (influx-net:8086) from another container by it's network name I'm obtaining nothing. Also when I do the same with 192.168.111.11:8086 (my pc IP), I'm getting a response. What is the problem? Local PC firewall is off.

Marcel Kopera
  • 179
  • 11

1 Answers1

0
# create a network
$ docker network create influx-net
# start influx db attached to the network influx-net
$ docker run -d --name idb --net influx-net influxdb

Now, create a new container attached to same network and try connecting:

$ docker run -it --net influx-net ubuntu 
root@fc26733c33da:/# telnet idb 8086
Trying 172.18.0.2...
Connected to idb.
Escape character is '^]'.

And it's working.


If you need to connect using IP, inspect the network to get container IP and then use the same to connect.

$ docker network inspect influx-net 
[
    {
        "Name": "influx-net",
        ...
        "Containers": {
            "844311255fb9dd74fee1df2dc65023533ad961d1dd6345128cc2c92237ba35e0": {
                "Name": "idb",
                "EndpointID": "b294cb0661f9f1166833f381a02bcbfa531cdeba6657c51b9595814f5ee323be",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",  # this one here
                "IPv6Address": ""
            }, ...
        },
        "Options": {},
        "Labels": {}
    }
]
$ docker run -it --net influx-net  ubuntu
root@360bbca6534d:/# telnet 172.18.0.2 8086
Trying 172.18.0.2...
Connected to 172.18.0.2.
Escape character is '^]'.
Tony
  • 130
  • 1
  • 1
  • 12
  • Your setup is the same as I did above, I don't know why, but when I added `--network-alias=influx-net` from this post it worked – Marcel Kopera Nov 10 '21 at 03:26