Run OpenWrt as container: Failed to connect to ubus

Hi, openwrt experts,

I am trying to test OpenWRT functionality as container, following the steps similar to: https://openwrt.org/docs/guide-user/virtualization/docker_openwrt_image
I used below Dockerfile to create docker image:

FROM scratch
ADD https://downloads.openwrt.org/releases/18.06.4/targets/x86/generic/openwrt-18.06.4-x86-generic-generic-rootfs.tar.gz /
RUN mkdir /var/lock && \
    opkg update && \
    opkg install uhttpd-mod-lua && \
    uci set uhttpd.main.interpreter='.lua=/usr/bin/lua' && \
    uci commit uhttpd
USER root
CMD ["/sbin/init"]

After creating docker container based on this image:
sudo docker run -it openwrt-1806 /bin/sh

I try to install mwan3 package to test multiple wan features, but get below errors like:

/ # opkg install mwan3
Configuring kmod-nfnetlink.
Configuring libmnl.
Configuring kmod-ipt-conntrack-extra.
Configuring kmod-ipt-ipopt.
Configuring iptables-mod-ipopt.
Configuring kmod-ipt-ipset.
Configuring libipset.
Configuring ipset.
Configuring ip-tiny.
Configuring iptables-mod-conntrack-extra.
Configuring mwan3.
Failed to connect to ubus
Failed to connect to ubus
Failed to connect to ubus
Failed to parse message data
sh: out of range
Failed to parse message data
sh: out of range
Failed to parse message data
sh: out of range
Failed to parse message data
sh: out of range

try to restart mwan3 application or simple run ubus list return same error:

/ # /etc/init.d/mwan3 start
Failed to connect to ubus
Failed to parse message data
sh: out of range
Failed to parse message data
sh: out of range
Failed to parse message data
sh: out of range
Failed to parse message data
sh: out of range

/ # ubus list
Failed to connect to ubus

It seems ubusd service is not running:

/ # ps -w 
  PID USER       VSZ STAT COMMAND
    1 root      1012 S    /bin/sh
  577 root      1008 R    ps -w

So are there any steps I missed when running openwrt in container to enable ubusd service and register other service with ubusd? and is there any place to find the syslog information?

Thanks much!

I had the same problem and I'm looking for the same solution to be able to run it inside docker container.

Does this run script work?