Building a Docker Instance for a Rasa Chatbot
I recently started the development of my chatbot through Rasa, a framework that provides a pipeline combining existing Natural Language Processing (NLP) technologies and Rasa Core, which determines how the chat bot should respond. The installation of Rasa itself is relatively straightforward. However, in the course of my development, I want to use a tool called Rasa X, which lets me generate and annotate training data for my chat bot by chatting with it without having to input the data manually into the file. Setting up Rasa X to train and run a chat bot is more complicated in that the default installation process would most likely result in errors, as it did for me. It requires several tweaks and specific instructions that can only be found through trial and error, and works better in a Linux environment. To ensure that I wouldn't have to reproduce these steps every single time I want to set up Rasa, and for the aforementioned Linux reason I decided to set up a Docker container, substituting these steps with a command or two instead. Here's how I did it:
docker pull jupyter/base-notebook:python-3.8.6
docker run -p 5005:5005 -p 5002:5002 -p 80:80 -p 8888:8888 --name rasa -e GRANT_SUDO=yes --user root -e JUPYTER_ENABLE_LAB=yes -v %cd%:/home/jovyan jupyter/base-notebook:python-3.8.6
Then, I ran the following commands inside the CLI prompt of the container to install specific versions of packages that work. The first two lines are critical since installing rasa-x normally with the default dependencies would otherwise lead to a lot of library conflicts. It also installs spaCy, an open source natural language processing library that will be used with Rasa.
pip3 install --upgrade pip==20.2
conda install ujson==1.35 -y
pip3 install rasa-x==0.39.3 --extra-index-url https://pypi.rasa.com/simple
pip3 install spacy==3.0.6 PyDictionary bs4 lxml mathparse discord click==7.1.1
spacy download en_core_web_md
Finally, all that's left to do is push your own container to Docker hub, replacing julianweng/cory with [yourdockerusername]/[anyprojectname]. On your host (Windows CMD), run the following.
docker commit rasa julianweng/cory:v1.0
docker tag julianweng/cory:v1.0 julianweng/cory:latest
docker push julianweng/cory:v1.0
docker push julianweng/cory:latest
The final product that I produced can be found at https://hub.docker.com/repository/docker/julianweng/cory. With this, you can quickly set up a Rasa project with Rasa X with all needed dependencies. If you just want to use the docker image and get started with Rasa instead, CD to the directory you want your bot to be in and run these commands instead.
docker run -d -p 5005:5005 -p 5002:5002 -p 80:80 -p 8888:8888 --name rasa -e GRANT_SUDO=yes --user root -e JUPYTER_ENABLE_LAB=yes -v %cd%:/home/jovyan julianweng/cory
rasa init --no-prompt