Error connecting with mysql on localhost from rasa action running in docker container

Hi everyone, I am new to Rasa.

action server is running in docker container and I am getting error in mysql database connection from the action server. Mysql database is also running on the localhost.

below is the exact error

default
<class 'str'>
default
Exception occurred while handling uri: 'http://action-server:5055/webhook'
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 236, in _open_connection
    self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Can't connect to MySQL server on '127.0.0.1:3306' (111)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/sanic/app.py", line 973, in handle_request
    response = await response
  File "/opt/venv/lib/python3.8/site-packages/rasa_sdk/endpoint.py", line 104, in webhook
    result = await executor.run(action_call)
  File "/opt/venv/lib/python3.8/site-packages/rasa_sdk/executor.py", line 398, in run
    action(dispatcher, tracker, domain)
  File "/app/actions/actions.py", line 66, in run
    mydb= mysql.connector.connect(
  File "/opt/venv/lib/python3.8/site-packages/mysql/connector/__init__.py", line 272, in connect
    return CMySQLConnection(*args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 85, in __init__
    self.connect(**kwargs)
  File "/opt/venv/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 1014, in connect
    self._open_connection()
  File "/opt/venv/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 241, in _open_connection
    raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)

Hello @laish Rahul and welcome to the forum!

Can you share the rasa --version and also endpoints.yml file? If you can even share docker or docker-compose file. Thanks.

I am running rasa 2.8.0, also endpoints.yml file attached endpoints.yml (1.4 KB) . Thanks

@laish can you share some other requested files as you said you are using docker container and connecting MySQL on the local machine is a different process and working on docker container using docker or docker-compose is different.

Welcome to the forum :slight_smile:

This only works if your MySQL server is in the same container as the action server. Make sure to set the IP correctly.

@laish Yes Chris is right, but every time we spin the docker container, the container creates the dynamic IP for the MySQL container (image). So that’s why I asked you to share the docker file for the same or you need to create the bridge network for the same.

1 Like

Thanks a lot for the information, I was running the Mysql server outside of the container on the host machine.

1 Like

You can do one of the following:

  • Put them in the same container (as Nik said) - Use localhost
  • Use two containers in the same Docker Network - Use localhost
  • Keep MySQL outside (as you’re doing) - Use IP

Anyway, is your problem solved now? :slight_smile: