ClientConnectionError when using callback and docker

Hello,

I run rasa in a docker container using docker compose on port 5005, and my app locally on localhost:8000. I recently added callback by adding a credentials.yml with this:

callback:
  url: "http://localhost:8000/bot"

My docker compose looks like this for rasa:

  rasa:
    build:  "./chatbot/"
    image: chatbot-rasa:latest
    ports:
      - "5005:5005"

When I run rasa from terminal instead of in a docker, it works fine, but when I use docker, I get an Error:

Exception occurred while handling uri: 'http://localhost:5005/webhooks/callback/webhook'
Traceback (most recent call last):
...
ConnectionRefusedError: [Errno 111] Connection refused

 The above exception was the direct cause of the following exception:

Traceback (most recent call last):
...
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:8000 ssl:default [Connection refused]

I guess Rasa cant make POST requests to localhost:8000 from inside the container for some reason. Any idea why? When i wasn’t using callback and all it had to do was reply to requests, it worked fine.

The error you’re seeing occurs because Rasa in your Docker container can’t reach localhost:8000 on your local machine. To fix this:

Replace localhost with your host machine’s IP in credentials.yml.

Example: url: “http://192.168.1.100:8000/bot

Alternatively, use host.docker.internal as the hostname.

Example: url: “http://host.docker.internal:8000/botblue prism

If both containers are in the same Docker Compose network, use the service name.

Example: url: “http://app-service-name:8000/bot

Choose the method that suits your setup, and it should resolve the issue.