RasaPi Running via Docker

Hello community and Docker aficionados!

@stephens did a fantastic start on trying to get a Docker image of the RasaPi system running on the Raspberry Pi. Here is his write-up:

He needs help getting it running - seems like there is some issues with opencv-python.

To replicate the errors, run the following as a script:

sudo echo "https://apt.dockerproject.org/repo/ raspbian-RELEASE main"
sudo apt-get install -y docker.io
sudo apt install python3-pip
sudo pip3 install docker-compose

Here is his Dockerfile:

# time sudo docker build -t rasapi:balena .
#FROM balenalib/raspberry-pi-debian:buster
# time sudo docker build -t rasapi:buster .
FROM debian:buster

RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
  libbz2-dev \
  libssl-dev \
  xz-utils \
  wget \
  curl \
  build-essential \
  cmake \
  unzip \
  pkg-config \
  zlib1g-dev \
  apt-utils \
  sudo

# Get and install Python3.6
RUN wget --no-check-certificate https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz && \
  tar -xvf Python-3.6.8.tar.xz && \
  cd Python-3.6.8 && \
  ./configure && \
  make -j4 && \
  make install

# Update Python3.6 packages
RUN python3.6 -m pip install --upgrade pip setuptools --user

# Install additional dependencies
# Enables access to Tensorflow whl
# Dependency for the h5py python package
RUN apt-get install python3-pip libhdf5-dev -y

RUN python3.6 --version

# Install Tensorflow
RUN python3.6 -m pip install tensorflow==1.14.0 -v --user --extra-index-url https://www.piwheels.org/simple

RUN  apt-get install -y --no-install-recommends \
  libjpeg-dev libpng-dev libtiff-dev \
  libavcodec-dev libavformat-dev libswscale-dev libv4l-dev \
  libxvidcore-dev libx264-dev \
  libgtk-3-dev \
  libcanberra-gtk* \
  libatlas-base-dev gfortran \
  python3-dev

WORKDIR /root

# Download OpenCV and clarify naming scheme
RUN wget --no-check-certificate -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip && \
  wget --no-check-certificate -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.0.zip && \
  ls -l

RUN unzip opencv.zip && \
  unzip opencv_contrib.zip && \
  mv opencv-4.0.0 opencv && \
  mv opencv_contrib-4.0.0 opencv_contrib

RUN ls -l

RUN cd opencv && \
  ls -l && \
  mkdir build && \
  cd build && \
  cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=/root/opencv_contrib/modules \
    -D ENABLE_NEON=ON \
    -D ENABLE_VFPV3=ON \
    -D BUILD_TESTS=OFF \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D INSTALL_PYTHON_EXAMPLES=OFF \
    -D BUILD_EXAMPLES=OFF .. && \
  make -j4 && \
  sudo make install && \
  sudo ldconfig

RUN apt-get install -y --no-install-recommends \
  dphys-swapfile \
  git

#RUN sudo /bin/sh -c "/sbin/dphys-swapfile setup"
#RUN cat /etc/dphys-swapfile

# Increasing swap size to make OpenCV
#RUN SWAPSIZE=2048 && \
#  sed -i "s/^CONF_SWAPSIZE.*/CONF_SWAPSIZE=${SWAPSIZE}/" /etc/dphys-swapfile && \
#  sudo /etc/init.d/dphys-swapfile stop && \
#  sudo /etc/init.d/dphys-swapfile start

# Link cv2 to Python3.6
RUN cd /usr/local/lib/python3.6/site-packages/ && \
  sudo ln -s /usr/local/python/cv2/python-3.6/cv2.cpython-36m-arm-linux-gnueabihf.so cv2.so

RUN cd ~ && \
  git clone https://github.com/explosion/spaCy && \
  git clone https://github.com/tensorflow/tensor2tensor && \
  git clone https://github.com/google/dopamine.git && \
  wget --no-check-certificate https://github.com/RasaHQ/rasa/archive/1.4.0.zip && unzip 1.4.0.zip

RUN sudo echo "[global]" > /etc/pip.conf && \
  sudo echo "extra-index-url=https://www.piwheels.org/simple" >> /etc/pip.conf && \
  sudo cat /etc/pip.conf

WORKDIR /root/dopamine

# Installing dopamine-rl
RUN cd ~/dopamine && \
  sed -i '/opencv-python/d' setup.py

RUN  echo grep opencf && \
  find . -exec grep -l "opencv" {} \; && \
  pwd && \
  ls -l
RUN  pwd && \
  cat setup.py && \
  python3.6 -m pip install . --user

# Installing tensor2tensor
RUN cd ~/tensor2tensor && \
  sed -i '/opencv-python/d' setup.py && \
  sed -i '/dopamine-rl/d' setup.py && \
  python3.6 -m pip install . --user --force-reinstall

# Installing other RASA dependencies
RUN sudo apt install libpq-dev/buster -y  && \
  python3.6 -m pip install psycopg2 --user

# Installing RASA
RUN cd ~/rasa-1.4.0 && \
  sed -i '/tensor2tensor/d' setup.py && \
  sed -i '/tensor2tensor/d' requirements.txt && \
  python3.6 -m pip install -r requirements.txt --user --force-reinstall && \
  python3.6 -m pip install . --user --force-reinstall

Finally, after saving this Dockerfile, run:

sudo docker build .

Can anyone help with running this Dockerfile and replicating on the Pi’s? Looping in @Tobias_Wochinger and @JulianGerhard to see if you know of anyone else who can help with this.

Thanks and anyone who helps here, let us know what you find out! I am going to be trying this at some point to see what I can uncover.

TheCedarPrince

1 Like

Like I mentioned in Slack I’ll work on this some over the weekend when I get home and have access to my pi’s.

Thanks again both of ya for this work, it’s gonna be a cool project IMO.

2 Likes

Hey @btotharye,

Awesome. Just a heads-up, the entire method has only been tested on the RPi4 with 4GB of RAM. Other Pi models might not be strong enough to handle this.

TheCedarPrince

ok cool I’ll test them just so we can confirm I have a mixture of different rpi’s at the house anyways.

1 Like

Hi @btotharye,

just to complete what @TheCedarPrince has written so far: Feel free to get back to me if there are any questions. I have tested everything in advance on a Raspi3 aswell. However what @TheCedarPrince wrote somewhere is true: don’t expect it to be a quick installation :smiley:

If you want to see the RasPi Prince wrote about in action you can ask Karen for the video.

Kind regards and have a nice weekend both of you Julian

1 Like