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.