BEST WAY 2 LINK ACTION SERVER AND RASA SERVER | DOCKER CONTAINER

link action server

OVERVIEW

In this blog, you will learn how you can link action server in one independent docker container to the Rasa server in another docker container. There are two ways of linking multiple docker containers together,
1. Linking containers by creating the network and,
2. Adding multiple services to docker-compose and to run them all together.

In our previous blogs, you may have seen how to create the docker container for rasa chatbot and to further customize them.

Linking containers by creating the network

For linking the multiple docker containers together you must first have at least two docker containers. Like in our case we already have one docker container for Rasa server. Now let’s pull another docker container for action server so that we can link them together. To do that open the terminal and go to your rasa project directory. Now execute the following commands.

mkdir actions
touch actions/__init__.py
mv actions.py actions/actions.py

Once this is done, now create a docker file and open it in any editor of your choice with the given command

touch Dockerfile
nano Dockerfile

and then add the below code to Dockerfile

#Extend the official Rasa SDK image
FROM rasa/rasa-sdk:1.10.2

#Use subdirectory as working directory
WORKDIR /app

#Copy any additional custom requirements, if necessary (uncomment next line)
#COPY actions/requirements.txt ./

#Change back to root user to install dependencies
USER root

#Copy actions folder to working directory
COPY ./actions /app/actions

#Install extra requirements for actions code, if necessary (uncomment next line)
#RUN pip install -r requirements.txt

RUN /opt/venv/bin/python -m pip install --upgrade pip
#By best practices, don't run the code with root user
USER 1000

Once you have added the above code just save it and exit. In the above code, we are mentioning what docker image we will use and what activities we will perform on it. Like as per the above code we will use the docker image as “rasa/rasa-sdk:1.10.2” and into that image, we are setting up the working directory as “/app”. After that inside this directory, we’ll copy the actions.py script and all the files associated with it. Also, if required you can install the packages used in the script.

Now let’s build the Dockerfile to pull the rasa-sdk image. Build it with the given command on the terminal,

docker build . -t rasa/rasa-sdk:1.10.2

The above command will execute all the code step by step as mentioned in the Dockerfile. After the successful execution of the command you will have the rasa/rasa-sdk:1.10.2 image installed on your system.

Now, let’s create a network which will link the rasa server to the action server,

docker network create action-link

With the above command, you have created a network with the name action-link. Now, let’s link this network to the action server and then link it to the rasa server. Use the below commands to link action server to the network,

docker run -d -v $(pwd)/actions:/app/actions --net action-link --name action-server-test rasa/rasa-sdk:1.10.2
LINK ACTION SERVER

With the above command, you have linked the action server to the network and also you have created the name “action-server-test” to the action server which will be used to link to the rasa server. Now, with respect to this name update the endpoints.yml file for the rasa server, update the action_endpoint with the given commands.

action_endpoint:
  url: "http://action-server-test:5055/webhook"

With the above steps now you have link action server to the rasa server. Now you can verify that rasa server is linked to the action server or not.

docker run -it -v $(pwd):/app -p 5005:5005 --net action-link rasa/rasa:1.10.8-full shell

Also, check this video for more clarity on implementing the things.

If everything goes right and you have link action server to the rasa server from different independent docker containers then you will see the output like this.

LINK ACTION SERVER

From the above demo I hope now you have got the clarity that how you can link action server and rasa server in different independent docker containers together with the help of creating a network.

In the next blog I’ll show you how you can link run multiple services together like we did in this blog, with the help of docker-compose which is the most efficient and advanced technique used in the industries.

For more understanding and clarification on rasa chatbot, you can check out the official website of rasa and docker hub. Also, you can check these video contents for the deployment of rasa Chabot on the live server with Google Cloud Platform and link it to the domain name.

This is all about how to link action server to the rasa server in different docker containers. I hope you have got a crystal clear understanding of it. But still, if you are facing any difficulties in understanding and implementing it. Feel free to leave a comment below in the comment section.

Stay Tuned and Happy Learning. 🙂

One thought on “BEST WAY 2 LINK ACTION SERVER AND RASA SERVER | DOCKER CONTAINER

Leave a Reply

Your email address will not be published. Required fields are marked *