05 กันยายน 2567

Running erisamoe/cloudflared on mikrotik container with 56MB tmpfs

Testing hardware
- hAP ax lite
- hAP ax2

/interface veth
add address=10.0.0.20/24 gateway=10.0.0.1 name=cf-tunnel

/interface bridge port
add bridge=br-lan interface=cf-tunnel
 
/container envs
add name=cf-tunnel key=TUNNEL_TOKEN  value=XXX

/disk
add slot=tmpfs tmpfs-max-size=56M type=tmpfs

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

/system script
add name=addCloudflared source=":delay 20s\
    \n/container remove [find tag~\"cloudflared\"]\
    \n:delay 5s\
    \n/container add remote-image=erisamoe/cloudflared:latest interface=cf-tunnel envlist=cf-tunnel cmd=\"tunnel run\" logging=yes root-dir=tmpfs\
    \n:delay 10s\
    \nwhile ([/container get [find tag~\"cloudflare\"] status] != \"running\") do={\
    \n    :delay 10s\
    \n    /container start [find tag~\"cloudflared\"]\
    \n}"

add name=restartCloudflared source=\
    "/container stop [find tag~\"cloudflared\"]\
    \nwhile ([/container get [find tag~\"cloudflare\"] status] != \"running\") do={\
    \n    :delay 3s\
    \n    /container start [find tag~\"cloudflared\"]\
    \n}"
    
/system scheduler
add name=startCloudflare on-event=addCloudflared start-time=startup

/system/script/run restartCloudflared