Skip to content

The ResIOT team created a single, fully configurable image for ResIOT LoRaWAN Network Server & IoT Platform, the name is resiot/resiot:1000020

note 1: at each reboot the resiot/resiot:1000020 image proceeds with automatic updating to the latest version available
note 2: at the first start, wait a couple of minutes to allow time to perform all the necessary configurations

Docker Stack Multi Instance Basic Example with LoRaWAN Gateway connected via UDP

This example allows you to create an example deployment with 3 ResIOT instances in HA with Docker stack
In this example we have:
IP of the server to be reached from the outside and from the gateways: 155.156.157.158
Tcp port to access the platform via web: 58089
ResIOT Platform access address is: http://155.156.157.158:58089
Tcp port for Grpc protocol: 58096
Grpc host for gateway connection: 155.156.157.158:58096
Udp port for gateway connection: 57678
persistent volume folders to backup: ./resiotdata , ./rdbdata , ./dbdata
persistent volume for use by ResIOT for automatic updates and files that do not need to be backed up: ./resiotupdfld

remember to open the firewall ports:
58089 TCP
58096 TCP
57678 UDP

this example includes two files docker-compose-stack.yaml and nginx.conf to be created in the same folder
follow the next three step

Step 1 - contents of docker-compose-stack.yaml file:

version: "3.2"
services:
   dbresiot:
     image: postgres:12.5-alpine
     volumes:
       - ./dbdata:/var/lib/postgresql/data
     restart: always
     environment:
       POSTGRES_USER: resiotdb
       POSTGRES_PASSWORD: yourpasswordtest
       POSTGRES_DB: resiotcore
       PGDATA: /var/lib/postgresql/data/pgdata
   rdb:
     image: redis:5.0.10-alpine
     volumes:
       - ./rdbdata:/data
     restart: always
   mqtt:
     image: eclipse-mosquitto
     restart: always
   resiot:
     depends_on:
       - dbresiot
       - mqtt
       - rdb
     image: resiot/resiot:1000020
     deploy:
       replicas: 3
     expose:
       - "8088"
       - "8095"
       - "7677/udp"
     volumes:
       - ./resiotupdfld:/run
       - ./resiotdata:/data
     restart: always
     environment:
       NO_LNS: "n"
       NO_PLA: "n"
       RESIOT_DB_TYPE: postgres
       RESIOT_DB_URL: postgres://resiotdb:yourpasswordtest@dbresiot:5432/resiotcore?sslmode=disable
       RESIOT_REDIS_URL: redis://rdb:6379
       RESIOT_MQTT_URL: tcp://mqtt:1883
       RESIOT_LORA_BAND: EU_863_870
       RESIOT_LORA_NETID: A0A1A2
       RESIOT_EXTERNAL_ACCESS_UDP_HOST: 155.156.157.158
       RESIOT_EXTERNAL_ACCESS_UDP_PORT: 57678
       RESIOT_EXTERNAL_ACCESS_GRPC_HOST: 155.156.157.158:58096
   nginx:
     image: nginx:latest
     volumes:
       - ./nginx.conf:/etc/nginx/nginx.conf:ro
     depends_on:
       - resiot
     ports:
       - "58089:58089"
       - "58096:58096"
       - "57678:57678/udp"

Step 2 - contents of nginx.conf file:

user  nginx;
events {
    worker_connections   1000;
}
http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
    upstream resiottcp_8088_backend {
        server resiot:8088;
    }
    server {
        listen 58089;
        location / {
                        proxy_pass http://resiottcp_8088_backend;
                        proxy_http_version 1.1;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection $connection_upgrade;
                        proxy_set_header Host $host;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header X-Forwarded-Proto http;
                        proxy_read_timeout 36000s;
                        proxy_redirect off;
        }
    }
    server {
        listen 58096 http2;
        location / {
                        grpc_pass grpc://resiot:8095;
        }
    }
}
stream {
    upstream resiotudp_7677_backend {
        server resiot:7677;
    }
    server {
        listen 57678 udp;
        proxy_pass resiotudp_7677_backend;
    }
}

Step 3 - Docker stack deployment

# in the folder where the docker-compose-stack.yaml and nginx.conf files are present i create the folders dbdata,rdbdata,resiotdata and resiotupdfld
# example for linux:
sudo mkdir dbdata ; sudo mkdir rdbdata ; sudo mkdir resiotdata ; sudo mkdir resiotupdfld

# docker stack deploy with name stack0001
sudo docker stack deploy --compose-file docker-compose-stack.yaml stack0001

(you can also use docker-compose with sudo docker-compose --compatibility up
for testing but without replication because on a machine it is not managed correctly as in particular configurations all the instances restart simultaneously losing the condition of ha)

# now visit http://155.156.157.158:58089 after two/three minutes

# Other commands:
# see active services
sudo docker stack services stack0001

# to see the logs
sudo docker service logs stack0001_resiot
sudo docker service logs stack0001_nginx
sudo docker service logs stack0001_dbresiot
sudo docker service logs stack0001_mqtt
sudo docker service logs stack0001_rdb

# to delete
sudo docker stack rm stack0001
sudo rm -rf dbdata ; sudo rm -rf rdbdata ; sudo rm -rf resiotdata ; sudo rm -rf resiotupdfld