You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

# jan/19/2023 11:04:17 by RouterOS 7.8alpha173
# software id = 
#
/interface bridge
add name=docker
/interface ethernet
set [ find default-name=ether1 ] disable-running-check=no
/interface veth
add address=172.17.0.2/24 gateway=172.17.0.1 name=veth1
/container mounts
add dst=/data name=tb-data src=/tb/data
add dst=/var/log/thingsboard name=tb-logs src=/tb/logs
/disk
set slot1 slot=slot1
set slot2 slot=slot2
set slot3 slot=slot3
set slot4 slot=slot4
set slot5 slot=slot5
set slot6 slot=slot6
set slot7 slot=slot7
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/system logging action
add disk-file-count=10 disk-file-name=container-log disk-lines-per-file=50000 \
    name=container target=disk
/container
add envlist=env interface=veth1 logging=yes mounts=tb-data,tb-logs root-dir=\
    Thingsboard
/container config
set ram-high=2048.0MiB registry-url=https://registry.mt.lv tmpdir=pull
/container envs
add key=TB_QUEUE_TYPE name=env value=in-memory
/interface bridge port
add bridge=docker interface=veth1
/ip settings
set max-neighbor-entries=14336
/ipv6 settings
set max-neighbor-entries=7168
/ip address
add address=10.55.8.247 interface=ether1 network=10.55.8.0
add address=192.168.1.101/24 interface=ether1 network=192.168.1.0
add address=172.17.0.1/24 interface=docker network=172.17.0.0
/ip dhcp-client
add interface=ether1
/ip dns
set servers=159.148.147.194
/ip dns static
add address=10.4.23.204 name=registry.mt.lv
/ip firewall nat
add action=masquerade chain=srcnat src-address=172.17.0.0/24
add action=dst-nat chain=dstnat dst-port=8080 protocol=tcp to-addresses=\
    172.17.0.2 to-ports=80
add action=dst-nat chain=dstnat dst-port=9090 protocol=tcp to-addresses=\
    172.17.0.2 to-ports=9090
/ip route
add gateway=192.168.1.254
/system logging
add action=container topics=container
[admin@MikroTik] > 

[admin@MikroTik] > container/add remote-image=thingsboard/tb-postgres:latest interface=veth1 envlist=env root-dir=Thingsboard mounts=tb-data,

tb-logs logging=yes

[admin@MikroTik] > 


Introduction

Docker allows...

Summary

Sub-menu: /container

note: container package is required.

RouterOS versions that are older than 7.x will not be able to run this scenario as they will not have a "SYSVIPC" feature added to the kernel that allows it to work.

Make sure to study our container guide before proceeding with the configuration. Make sure to check the disclaimer and requirements sections to understand all the risks and necessary steps you might be required to do.

In this example, we will run it on a Cloud Hosted Router (CHR) device. To help you set it up in a Virtual Box, please check our youtube tutorial.

At the time, when the guide was published, thingsboard/tb-postgres image was available for linux/arm64 and linux/amd64 OS/architectures only. Meaning, you are not able to run this scenario on our arm32-bit architecture RouterOS devices.

There is a couple of parameters to keep in mind:

a) You need to understand that it is a server and that you will need to have additional space for the data that is stored there and the image itself. In our tests, 8 GB of disk space was plenty enough but! you might want to consider adding more for real-life applications, especially if you are planning on running more containers. Just remember → it might be better to have a reserve.

b) Same as with the disk space, RAM memory is also important. Per the ThingsBoard documentation, when using a single instance of ThingsBoard with a PostgreSQL database, it is recommended to allocate at least 1GB of RAM and use a minimum load (a few messages per second). 2-4GB RAM is recommended. In other words, if you want to run it on a RouterBoard device, please understand, that you will not be able to run it on devices that have less than 1 GB RAM (every device should have information about its RAM under their respective specification page, so make sure to check it) and, even better, consider having a device with more memory to spare.

Check the tips and tricks section to understand how to limit RAM and our recommendations about disks we advise using.

Configuration

Container mode

Enable container mode:

/system/device-mode/update container=yes

You will need to confirm the device-mode with a press of the reset button, or a cold reboot, if using container on X86.

Networking

Add veth interface for the container:

/interface/veth/add name=veth1 address=172.18.0.2/24 gateway=172.18.0.1

Create a bridge for containers and add veth to it:

/interface/bridge/add name=dockertb
/ip/address/add address=172.18.0.1/24 interface=dockertb
/interface/bridge/port add bridge=dockertb interface=veth1

Setup NAT for outgoing traffic:

/ip/firewall/nat/add chain=srcnat action=masquerade src-address=172.18.0.0/24

Forward required ports to the container (where 192.168.88.1 is the router's IP address). Per the image default configuration, ThingsBoard uses 9090 TCP port for HTTP management/GUI:

/ip firewall nat
add action=dst-nat chain=dstnat dst-address=192.168.88.1 dst-port=9090 protocol=tcp to-addresses=172.18.0.2 to-ports=9090

And for MQTT connection, 1883 TCP:

/ip firewall nat
add action=dst-nat chain=dstnat dst-address=192.168.88.1 dst-port=1883 protocol=tcp to-addresses=172.18.0.2 to-ports=1883


Environment variables and mounts

Check docker-thingsboard documentation for exact mounts and variables that need to be added.

Environment variables:

/container/envs/add name=tb_envs key=TB_QUEUE_TYPE value="in-memory"

Mounts:

/container/mounts/add name=mytb-data src=tb/mytb-data dst=/data
/container/mounts/add name=mytb-logs src=tb/mytb-logs dst=/var/log/thingsboard

Getting image

To simplify the configuration, we will get the image from an external library but you can also import it via the .tar file.

Make sure that you have "Registry URL" set accordingly, limit RAM usage, and set up a directory for the image.

/container/config/set registry-url=https://registry-1.docker.io tmpdir=pull ram-high=2048.0MiB

Pull image:

/container/add remote-image=thingsboard/tb-postgres:latest interface=veth1 root-dir=ThingsBoard mounts=mytb-data,mytb-logs envlist=tb_envs logging=yes

After running the command, RouterOS should start "extracting" the package. Check "File System" for newly created folders and monitor container status with the command /container/print.

Starting the container

After you make sure that the container has been added and the status changed to status=stopped after using /container/print → you can initiate it:

/container/start 0
  • No labels