Skip to content

Container on Mikrotik

0. Brief

From Mikrotik ROS 7.4 Beta 4, Mikrotik add new feature of Container.

Configurations are based on Mikrotik RouterOS 7.13.1 .

1. Enable Container mode

Login Terminal in RouterOS, with following commands:

/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.

2. Create network

Bridge Mode

(1). Add bridge veth interface for the container:

/interface/veth/add name=veth1 address=172.17.0.2/24 gateway=172.17.0.1

(2). Create a bridge for containers and add veth to it:

/interface/bridge/add name=containers
/ip/address/add address=172.17.0.1/24 interface=containers
/interface/bridge/port add bridge=containers interface=veth1

(3). Setup NAT for outgoing traffic:

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

Host Mode

(1). Add host veth interface for the container:

/interface/veth/add name=veth1 address=LAN_ADDRESS gateway=GATE_WAY_OF_LAN

(2). Add veth to LAN bridge

/interface/bridge/port add bridge=LAN_BRIDGE interface=veth1

3. Define mounts (optional):

/container/mounts/add name=smartdns src=/smartdns.conf dst=/etc/smartdns/smartdns.conf

4. Add container image

From an external library

(1). Set registry-url

/container/config/set registry-url=https://registry-1.docker.io

(2). Pull image

/container/add remote-image=dashdreams/smartdns:latest interface=veth1 \
root-dir=/smartdns hostname=smartdns mounts=smartdns workdir=/root

Import image from PC

/container/add file=smartdns.tar interface=veth1 root-dir=/smartdns \
hostname=smartdns mounts=smartdns workdir=/root

5. Start container

/container/start 0

6. Forward ports to internal container (optional)

Ports can be forwarded using dst-nat (where 192.168.88.1 routers IP address):

/ip firewall nat
add action=dst-nat chain=dstnat dst-address=192.168.88.1 dst-port=5353 protocol=tcp to-addresses=172.17.0.2 to-ports=53

Notes

How to get a local container image:

docker pull dashdreams/smartdns:latest@sha256:XXXXXXXXXXXXXXXXXXXXXXX
docker save dashdreams/smartdns > smartdns.tar

REF

[1]. https://help.mikrotik.com/docs/display/ROS/Container

[2]. http://www.irouteros.com/?p=2712