Docker / Action server error: Failed to run custom action / Couldn't connect to the server

I’m trying to get docker working so I can deploy it to a server for testing.
Here is my docker-compose.yml file

services:
  rasa:
    image: rasa/rasa:latest-full
    ports:
      - 5005:5005
    volumes:
      - ./:/app
    command:
      - run
      - --cors
      - "*"
      - --enable-api
      - --log-file
      - out.log
    depends_on:
      - action-server
  action-server:
    image: rasa/rasa-sdk:latest
    volumes:
      - ./actions:/app/actions
    ports:
      - "5055:5055"

I have an actions directory off my project root (where I’m running docker-compose up from. Inside I have and empty __init__.py and actions.py.

When I run docker-compose up I see the action server start up as well as the Rasa server -

Recreating rasa4_action-server_1
Recreating rasa4_rasa_1
Attaching to rasa4_action-server_1, rasa4_rasa_1
action-server_1  | 2019-10-11 16:16:35 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
action-server_1  | 2019-10-11 16:16:35 INFO     rasa_sdk.executor  - Registered function for 'solution9_form'.
action-server_1  | 2019-10-11 16:16:35 INFO     rasa_sdk.executor  - Registered function for 'erms_form'.
action-server_1  | 2019-10-11 16:16:35 INFO     rasa_sdk.endpoint  - Action endpoint is up and running on http ('0.0.0.0', 5055)
rasa_1           | 2019-10-11 16:16:40 INFO     root  - Starting Rasa server on http://localhost:5005

When submit a chat that is supposed to activate an action the console spits out this error

rasa_1           | 2019-10-11 16:16:57 ERROR    rasa.core.actions.action  - Failed to run custom action 'erms_form'. Couldn't connect to the server at 'http://localhost:5055/webhook'. Is the server running? Error: Cannot connect to host localhost:5055 ssl:None [Connection refused]
rasa_1           | 2019-10-11 16:16:57 ERROR    rasa.core.processor  - Encountered an exception while running action 'erms_form'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.

In the previous block it looks as though the action server is running in 5055, so any idea why it can’t be found? When I stop it stops the action server container

Stopping rasa4_rasa_1 ... done
Stopping rasa4_action-server_1 ... done   

Any ideas what I’m doing wrong?

I solved my problem. With docker, I needed to change the action_endpoint url in endpoints.yml to

  url: "http://rasa4_action-server_1:5055/webhook"

NOTE: YOUR NAME WILL BE DIFFERENT!

Once I did that, it worked.

Which now that I think about it, makes perfect sense. My webchat sends messages to localhost port 5005, which the Rasa server is mapped to. When I hit something that needed an action, Rasa would attempt to call the action server using the endpoint url which was url: "http://localhost:5055/webhook" but as you can see that was attempting to hit port 5055 INSIDE the rasa server docker container.

Once I changed that to use the docker instance name (rasa4_action_server_1) it was able to communicate with the action server in the other container. Just make sure you use YOUR docker’s instance name, not mine.

Hope that helps someone else.

2 Likes

HI Jonathan!! I wanted to have a further explanation! I ran into your same problem, I also opened a thread about it: Custom action Don't Work!. since I’m not very practical, in my case what should I write in place of localhost ?? you wrote this: url: “http: // rasa4_action-server_1: 5055 / webhook”. where can I get the information to insert in the string? thank you very much!!

@Daniele_mirabella_ITA When you do docker-compose up you could see a docker container will be created.
Eg: rasa_action_server_container

Instead of localhost you can mention container name. URL will look something like this http://rasa_action_server_container:5055/webhook

Also add your url in url in endpoints.yml, as action server runs on separate port rasa server when triggering action it will call this action server.

Note this is only when using docker.

1 Like

hello @Archish27 and thanks for your answer !!! when I run the docker-compose up command, powershell give me this error: PS C: \ Users \ Daniele \ Documents \ Workspace_Python \ Deep_Learning \ ringo_bot> docker-compose up ERROR: Can’t find a suitable configuration file in this directory or any parent. Are you in the right directory?

     Supported filenames: docker-compose.yml, docker-compose.yaml

so I tried to see if docker-compose was installed with the command PS C: \ Users \ Daniele \ Documents \ Workspace_Python \ Deep_Learning \ ringo_bot> docker-compose version docker-compose version 1.25.5, build 8a1c60f6 docker-py version: 4.1.0 CPython version: 3.7.4 OpenSSL version: OpenSSL 1.1.1c 28 May 2019PS

at this point: where can I find the docker-compose.yml file ??? i need the docker-compose.yml path to run the command!

Ugh! I would call someone experienced with team viewer and I would get everything sorted out !! I’m sure anyone in this forum would be able to settle the matter in 5 minutes !! :stuck_out_tongue:

No worries, docker takes a bit to get used to.

the docker-compose.yml file is a configuration file that tells docker how to build a stack of containers. That means, it will fire up a single container for each service (chat server / action server / chatUI / etc.) all with one command. It’s pretty sweet, especially if you’re used to opening up multiple consoles to launch each service.

I’ve attached my docker-compose.yml file to this reply.

To use it, you just need to do a couple things

  • create an actions directory off your project root
  • move actions.py into it
  • copy __init.py__ from your project root into it

Some other items of note: the volumes: lines tell Docker what local directories to mount and where in the docker container to mount them to. For example the actions server is mounting ./actions (the actions directory you created above) and that will be referenced from ./app/actions inside the action server container. You’ll see the same thing under the rasa server. These mappings allow you to continue to develop / train, etc locally and those files will be available inside docker. That said, you’ll still need to stop / start the docker containers.

You can also comment out the mysql server, I use that as my Tracker Store database

Drop the file into your rasa project directory run docker-compose up and should be good to go.

docker-compose up will keep the terminal live, and you’ll see all the logs for each of the services you’re firing up. You can also run docker-compose up -d and that will launch them in the background and give you your terminal back. To then stop them all you can docker-compose down and they’ll all stop.

When I first started out, I never used the -d flag because I like to watch logs as I test and develop. After a while you want your cursor back :slight_smile: The -d flag is handy because you can then stop different containers, so if for example you’re editing your actions.py file, you can just stop and restart the action server instead.

That should get you started. But you can also take a look a the docker-compose docs for more info

Here’s my file : docker-compose.yml (490 Bytes)

@jonathanpwheat First of all, THANKS INFINITE! with your careful and meticulous explanation I solved in part the problem. and I think i am so close to solve the error that I feel it!!

in summary: I delete all … I did the init of rasa so as to have a clean and new project. after I activated the endpoint, I raised comments in action.py and inserted the action “action_hello_world” both in domain and in stories. I created an “actions” folder inside my project where I inserted the action.py and then a copy of init.py file after I always copied the docker-compose file you provided inside the project (not in the actions folder). then …

  1. I started docker compose without -d, you can so also see the directory of my project

  1. in another terminal I started the training and then the shell
  2. I input “hello”
  3. the bot only returned the answer without the action, but very importantly, it did not return any errors in the output

  1. I then started docker run -it -v $ {pwd}: / app rasa / rasa: latest-full interactive (to understand the percentages of choosing the bot and to force a sort of response of the action) and putting "Y "the choice of action returns the error back to me!

while I’m writing I tried a second time and the program gave me the usual error … -.- "

I think I miss some little tricks, I realized that in your docker file he composed:

action-server: container_name: rasa-action-server image: rasa / rasa-sdk: latest volumes: - ./actions:/app/actions ports: - “5055: 5055”

ports: - “5055: 5055” is commented, should I remove the comment? thanks a lot for any other help !!!

@JulianGerhard hi! I see you are a rasa superhero!i read some topics where you help succeffully people with rasa!!! ^^ … could you read my post and help me please!!! thank you!!!

EDIT*: I just wrote an article on how to do all of this here - Using Docker with Rasa for development - DEV

@Daniele_mirabella_ITA - Keep reading because address your specific issue here. I think you may be doing a couple extra things that may be complicating the issue.

You’ll want to run rasa train and make changes to your actions.py file before docker-compose up

One thing to understand is that the docker-compose.yml file will launch Both the Rasa server and action server. If you don’t have a web-chat interface, or other channel (Telegram / Slack, etc) to chat with Rasa and are going to use use rasa shell to do your interaction, then you don’t want to run the rasa-server with docker compose, you can comment out lines 4-19 and just launch the action server.

It sounds like you stopped the docker containers when you ran step 5 above. That statement you executed only runs the rasa server in interactive mode, and does not launch the action server, so when you did that there wasn’t an action server running. Which isn’t actually the reason for the red errors in your screenshot.

The important thing to realize with Docker is “localhost” is local to the container itself, not your machine, so the action server url in endpoints.yml will need to be the name of the action-server docker service name. In your screenshot it looks like the url was still set to http://localhost:5055/webhook and the interactive shell was looking for an action server local on your machine, not in a docker container.

NOW, you could run the docker statement you executed in step 5, AND open a new terminal and do rasa run actions and everything would work.

I played around and can’t seem to get interactive mode to work with docker-compose. So if you want to use docker compose -

  1. comment out lines 9-14 so it just runs the action server
  2. change the url in endpoints.yml to url: "http://action-server:5055/webhook"
  3. run docker-compose up -d 4 run the interactive statement you mentioned in step 5 or alternate 4 run rasa shell interactive
1 Like

Hi @Daniele_mirabella_ITA,

I think @jonathanpwheat already mentioned the important points. You should follow them and see if they lead to success. If they don’t, feel free to come back to me and then I’ll start investigating those issues.

I have to admit that the docker-compose.yml seen in one of the images would not exactly be the way I would use rasa dockerized. I did a lot of experiments with Docker and started to use a complete Ubuntu 18.04 with rasa and everything related installed since this allowed me to simply bridge to a rasa command via docker, e.g. docker exec -it <id> rasa shell which then started the shell. Of course there exist various approaches and all of them have their advantages and disadvantages, but if you are not very familiar with Docker, then probably an easier setup would be a good idea.

I’d strongly recommend thinking about using Rasa X since the pack would be complete then and I’d favor the Rasa X interface for interactive learning over the shell version.

Those are only my two cents and those can be ignored!

Kind regards
Julian

1 Like