Hello,
I recently deployed rasa x with docker compose
the problem is that in my custom actions i have some mysql request (retrieve some data on local database)
when i run the docker-compose up -d
i am able to talk to the bot and run the custom actions, but the connection to the database is not working.
Should i declare a mysql part in the docker-compose file ? do you have some examples ?
Thanks @nik202 for he suggestion (maybe if you can help too it would be great)
@nik202 I have in my linux mysql machine install locally in which there is a rasa_bot database.
When a user talks to the bot, the bot invokes the custom action that is correct for the given intention and searches the rasa database for the answer.
This is possible thanks to a configuration file located in the actions folder in which we provide connection information (those of mysql-connector)
without docker-compose this works however with docker compose, the connection to the database does not work
@nik202 is it possible to connect my local database to the docker environment? on the other hand I do not know if it is necessary to completely run rasa, rasa-sdk and mysql in docker-compose environment
this is the configuration of the dbfile
import mysql.connector
import traceback
def getData(query:str):
"""
@query: sql query that needs to be executed.
returns the data being executed in "List" format
"""
try:
# Setup the connection.
# Pass your database details here
mydb = mysql.connector.connect(
host="10.10.0.15:3306",
user="toor",
password="toor",
database="mydb"
)
# set up the cursor to execute the query
cursor = mydb.cursor()
cursor.execute(query)
# fetch all rows from the last executed statement using `fetchall method`.
results = cursor.fetchall()
return results
except:
print("Error occured while connecting to database or fetching data from database. Error Trace: {}".format(traceback.format_exc()))
return []
@M_R_LY
I hope you are aware of the tracker store? try update the endpoints.yml for your current database
tracker_store:
type: SQL
dialect: "mysql+pymysql" # the dialect used to interact with the db
url: "localhost" # (optional) host of the sql db, e.g. "localhost"
db: "rasa" # path to your db
username: "root" # username used for authentication
password: "root" # password used for authentication
@M_R_LY Please be clear what you using MySQL or Postgres, as you shown in the code you using 3306 which is the port of Mysql and on the other hand, Postgres run on port 5432. I hope you understand my point.
Hi @nik202 i understand your confusion, that configuration in the endpoints.yml has been automatically generated by the rasa-x docker compose installation and its using Postgres for the tracker store.
Which have nothing to do with my little configuration that i have in my actions file in order to search for some informations in my database (the second image in my last post).
@nik202 there is a part In my my custom actions where i need to connect to my mysql database, search for some data and display it
I would suggest you containerize your database and bundle it with existing rasa docker set-up.
This tutorial guides you on how to containerize your DB and bundle it with an app.
@M_R_LY I can’t see your rasa or rasa-x only rasa-sdk in docker file? How you managing the rasa? Are you sure you able to run rasa using docker or docker-compose file?
i just had to allow my user to connect from my ip (the container ip) in my local database
GRANT ALL ON database_name.* to 'database_username'@'192.168.208.10' IDENTIFIED BY 'database_password';
FLUSH PRIVILEGES;
you must specify this too the ip of your database
@nik202
I managed to run also multiple bot in the same server just
follow the download step and for the configuration , change the port number for the
RASA_X_HOST (by default 5002)
the
RASA_USER_APP (by default 5055)
and the
RASA_PRODUCTION_HOST (by default 5005)
for the second bot (or the others)
Change also the nginx service port
ports:
- "8080:8080" (by default for the first bot ) to "8081:8080" (for the second bot)
- "443:8443" (by default for the first bot) to "444:8443" (for the second bot)
and in the browser specify the port for both bot
@nik202 maybe i will do a thread if i got some time
Thanks for the help