ChirpStack Learning Notes 2.8.1 Typical Problem Handling for Connecting a ChirpStack Container to a Native InfluxDB Container

Article Directory

Preface

stay 2.8 Application Integration InfluxDB An issue with the inability to connect the influxdb container was noted in this note, which is an in-depth analysis.

Young hands have recently been learning about the ChirpStack project, which should be the most influential LoRaWAN server open source project.It is a good learning material because of its rich components and readable code.Learn more about notes, Click here to view.

1 Problem Description

appserver_1      | time="2020-02-07T10:24:34Z" level=error msg="integration/multi: integration *influxdb.Integration error" error="sending measurements error: http request error: Post http://localhost:8086/write?db=db0&precision=ms&rp=: dial tcp 127.0.0.1:8086: connect: connection refused"

The container for ChirpStack is already running on my host machine, another InfluxDB container is opened as required by the application, prompting connection refused when configuring localhost:8086 as the connection address for InfluxDB on the chirpstack page.

2 Reason Analysis

The docker is a virtual environment, 127.0.0.1 and localhost refer to the internal virtual environment, not the external host, so this is not accessible.

2.1 Container Network Analysis

# docker network ls
NETWORK ID          NAME                        DRIVER              SCOPE
02231307198a        bridge                      bridge              local
81b1d878dd80        host                        host                local
5284403f2094        lora-app-server_default     bridge              local
8de8416ca11a        lora_default                bridge              local
d4389dfb8f38        loraserver-docker_default   bridge              local
49d4a4343b5e        lorawan-stack-dev_default   bridge              local
194a422ad895        none                        null                local

lora-app-server_default

# docker network inspect lora-app-server_default
[
    {
        "Name": "lora-app-server_default",
        "Id": "5284403f20943bcca33e6fb7482aa1c5e714bbf05a66c5712500f35c901f1a5d",
        "Created": "2019-10-29T12:37:30.514317558+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "192.168.16.0/20",
                    "Gateway": "192.168.16.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "46e4075d8376bd54b2d59d330a2f9924a0dff32e080f53b26200ce7845a6f65c": {
                "Name": "lora-app-server_mosquitto_1",
                "EndpointID": "5677bc3efacb3454d2e70d490e8c6d2bc75469080d985645ceda500940311944",
                "MacAddress": "02:42:c0:a8:10:04",
                "IPv4Address": "192.168.16.4/20",
                "IPv6Address": ""
            },
            "92ee8b9f02e044c77765e723717788d67ea7434b222191e3bd9a019dc31fd17e": {
                "Name": "lora-app-server_postgres_1",
                "EndpointID": "0c032e0946d397ee09f14deac9cf0039c3a5bba99e8a88fcfe942a7661e322d8",
                "MacAddress": "02:42:c0:a8:10:02",
                "IPv4Address": "192.168.16.2/20",
                "IPv6Address": ""
            },
            "e4201031eb7e4d4a34a165f38b8871de1e6527c16cc1cf9021993d6ec0793b11": {
                "Name": "lora-app-server_redis_1",
                "EndpointID": "c0b595b4f7a7fa3848aa57c9b65b77158ee16ed0ed8a744e580f68f0dac5878f",
                "MacAddress": "02:42:c0:a8:10:03",
                "IPv4Address": "192.168.16.3/20",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

loraserver-docker_default

# docker network inspect loraserver-docker_default
[
    {
        "Name": "loraserver-docker_default",
        "Id": "d4389dfb8f38d6a023de63ca25d74c65a5b4b114fbb83a1b43263e376000a22b",
        "Created": "2020-02-05T14:23:44.985567025+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "192.168.64.0/20",
                    "Gateway": "192.168.64.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "0329aa3dbabb76ab7d94cd19ff0ff89a8c48cc45d710b8060800a177dc2dd214": {
                "Name": "loraserver-docker_appserver_1",
                "EndpointID": "1080f620260de45592ac7c824f2e7a2f68846de5764e2734cd2f0745718c326a",
                "MacAddress": "02:42:c0:a8:40:07",
                "IPv4Address": "192.168.64.7/20",
                "IPv6Address": ""
            },
            "0d8afb7896f6d5ad7516c8079b2b38f6c88f2beac13ccb887273f62cd2d10538": {
                "Name": "loraserver-docker_geoserver_1",
                "EndpointID": "4775a6fb238a594972d8fbac20175537dc4fd83572051283484522777f42ecc5",
                "MacAddress": "02:42:c0:a8:40:04",
                "IPv4Address": "192.168.64.4/20",
                "IPv6Address": ""
            },
            "4bb2a05b99aa24a524137bbc4df3bd7e19bc8e45edd558c3bfda1d0530fc5c0b": {
                "Name": "loraserver-docker_postgresql_1",
                "EndpointID": "8e5e035a17bca1b957dc9c2d00ef385118407ad04bff87da3ca2009bfe7eeee5",
                "MacAddress": "02:42:c0:a8:40:06",
                "IPv4Address": "192.168.64.6/20",
                "IPv6Address": ""
            },
            "5e5813773f6dbc0af8136e234df9f6fd9658488fcafdf57dfdafd57cb9198c76": {
                "Name": "loraserver-docker_gatewaybridge_1",
                "EndpointID": "9e1956f9ed7f5cd4ca1009788a811ec243428ca4b0787b621f402b06c827375b",
                "MacAddress": "02:42:c0:a8:40:08",
                "IPv4Address": "192.168.64.8/20",
                "IPv6Address": ""
            },
            "9b8a1f733e2b3e995eaac5fcdd759ea7f4926943e511f3754c66293e7910ce6e": {
                "Name": "loraserver-docker_loraserver_1",
                "EndpointID": "ffc5869e673c591776f07d7fc5ab95ab017c9773dd11aa403010c69551b373a0",
                "MacAddress": "02:42:c0:a8:40:05",
                "IPv4Address": "192.168.64.5/20",
                "IPv6Address": ""
            },
            "c984f4f533bd904469a6afe70224baade7fffa550b345580bfe911e38235581e": {
                "Name": "loraserver-docker_redis_1",
                "EndpointID": "d7ebab7f77eac0beb71f207b94c7432ab04092c2c5442eeeaa1d87c7783085a1",
                "MacAddress": "02:42:c0:a8:40:02",
                "IPv4Address": "192.168.64.2/20",
                "IPv6Address": ""
            },
            "cc5400f93f5454ee5033f37a8b8bd584a292429baaa7c9fd16e788bd34200407": {
                "Name": "loraserver-docker_mosquitto_1",
                "EndpointID": "d47e177c7785d3a0f9c0e70e707bfdfb7cbb056f1b785bfc136a503559d7d929",
                "MacAddress": "02:42:c0:a8:40:03",
                "IPv4Address": "192.168.64.3/20",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "loraserver-docker",
            "com.docker.compose.version": "1.24.1"
        }
    }
]

2.2 Container Network Combing

bridge 172.17.0.1

  • influxdb 172.17.0.2

lora-app-server_default 192.168.16.1

  • lora-app-server_mosquitto_1
  • lora-app-server_postgres_1
  • lora-app-server_redis_1

loraserver-docker_default 192.168.64.1

  • loraserver-docker_appserver_1
  • loraserver-docker_gatewaybridge_1
  • loraserver-docker_loraserver_1
  • loraserver-docker_geoserver_1
  • loraserver-docker_postgresql_1
  • loraserver-docker_mosquitto_1
  • loraserver-docker_redis_1

To sum up, loraserver-docker_appserver_1 and influxdb are not on the same network and therefore cannot communicate.

The exact reason can be seen Docker Official Tutorial Practice Customizing bridge Networks.

3 Processing scheme

Scheme 1 Bridge ip is the host ip

The influxdb container exposes port 8086, so it can be located directly through the host IP and the exposed port.

The host IP is the bridge IP, which is the Docker0 IP address, for reference:
https://nickjanetakis.com/blog/docker-tip-65-get-your-docker-hosts-ip-address-from-in-a-container

# ip a
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:5f:e8:7c:be brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

So we can locate the influxdb container by 172.17.0.1:8086.We can configure the InfluxDB integration API endpoint in the chirpstack webui as follows:

http://172.17.0.1:8086/write

Scenario 2 connects the influxdb container to the same network

# docker network connect loraserver-docker_default influxdb
# docker network inspect loraserver-docker_default 
[
    {
        "Name": "loraserver-docker_default",
        "Id": "d4389dfb8f38d6a023de63ca25d74c65a5b4b114fbb83a1b43263e376000a22b",
        "Created": "2020-02-05T14:23:44.985567025+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "192.168.64.0/20",
                    "Gateway": "192.168.64.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": true,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "0329aa3dbabb76ab7d94cd19ff0ff89a8c48cc45d710b8060800a177dc2dd214": {
                "Name": "loraserver-docker_appserver_1",
                "EndpointID": "1080f620260de45592ac7c824f2e7a2f68846de5764e2734cd2f0745718c326a",
                "MacAddress": "02:42:c0:a8:40:07",
                "IPv4Address": "192.168.64.7/20",
                "IPv6Address": ""
            },
            "0d8afb7896f6d5ad7516c8079b2b38f6c88f2beac13ccb887273f62cd2d10538": {
                "Name": "loraserver-docker_geoserver_1",
                "EndpointID": "4775a6fb238a594972d8fbac20175537dc4fd83572051283484522777f42ecc5",
                "MacAddress": "02:42:c0:a8:40:04",
                "IPv4Address": "192.168.64.4/20",
                "IPv6Address": ""
            },
            "4bb2a05b99aa24a524137bbc4df3bd7e19bc8e45edd558c3bfda1d0530fc5c0b": {
                "Name": "loraserver-docker_postgresql_1",
                "EndpointID": "8e5e035a17bca1b957dc9c2d00ef385118407ad04bff87da3ca2009bfe7eeee5",
                "MacAddress": "02:42:c0:a8:40:06",
                "IPv4Address": "192.168.64.6/20",
                "IPv6Address": ""
            },
            "5e5813773f6dbc0af8136e234df9f6fd9658488fcafdf57dfdafd57cb9198c76": {
                "Name": "loraserver-docker_gatewaybridge_1",
                "EndpointID": "9e1956f9ed7f5cd4ca1009788a811ec243428ca4b0787b621f402b06c827375b",
                "MacAddress": "02:42:c0:a8:40:08",
                "IPv4Address": "192.168.64.8/20",
                "IPv6Address": ""
            },
            "98b72943ab195564fb1a8465243bff96cbc7dc989a3a16dab5269afc835336f5": {
                "Name": "influxdb",
                "EndpointID": "b89b8104bcf27a29bc3a7b470206a4669e5513b37d09e888ab970425299a807c",
                "MacAddress": "02:42:c0:a8:40:09",
                "IPv4Address": "192.168.64.9/20",
                "IPv6Address": ""
            },
            "9b8a1f733e2b3e995eaac5fcdd759ea7f4926943e511f3754c66293e7910ce6e": {
                "Name": "loraserver-docker_loraserver_1",
                "EndpointID": "ffc5869e673c591776f07d7fc5ab95ab017c9773dd11aa403010c69551b373a0",
                "MacAddress": "02:42:c0:a8:40:05",
                "IPv4Address": "192.168.64.5/20",
                "IPv6Address": ""
            },
            "c984f4f533bd904469a6afe70224baade7fffa550b345580bfe911e38235581e": {
                "Name": "loraserver-docker_redis_1",
                "EndpointID": "d7ebab7f77eac0beb71f207b94c7432ab04092c2c5442eeeaa1d87c7783085a1",
                "MacAddress": "02:42:c0:a8:40:02",
                "IPv4Address": "192.168.64.2/20",
                "IPv6Address": ""
            },
            "cc5400f93f5454ee5033f37a8b8bd584a292429baaa7c9fd16e788bd34200407": {
                "Name": "loraserver-docker_mosquitto_1",
                "EndpointID": "d47e177c7785d3a0f9c0e70e707bfdfb7cbb056f1b785bfc136a503559d7d929",
                "MacAddress": "02:42:c0:a8:40:03",
                "IPv4Address": "192.168.64.3/20",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "loraserver-docker",
            "com.docker.compose.version": "1.24.1"
        }
    }
]

This allows us to access the container directly through the container name influxdb or through the container ip 192.168.64.9.

So we can configure the InfluxDB integration API endpoint in the chirpstack webui as follows:

http://influxdb:8086/write

Or:

http://192.168.64.9:8086/write

4 Summary

This note starts with a typical problem that chirpstack's app_server container external influxdb cannot be connected through localhost. It analyses the container network involved in chirpstack, and gives two solutions for this problem, i.e., network bridge IP is host ip, influxdb container is also connected to the same container network.

END

241 original articles were published. 229 were praised. 800,000 visits+
His message board follow

Tags: network InfluxDB Docker

Posted on Sun, 09 Feb 2020 19:22:36 -0500 by kirannalla