Docker for Rasa


(Datisto) #1

Hey,

I have built my bot with NLU and Core and use the GUI from https://github.com/scalableminds/chatroom. I also read this nice blog: http://smithstrategy.com/index.php/2018/03/14/chatbot-tutorial-nlu-in-docker-container/

My bot looks just like that.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import logging

from rasa_core.agent import Agent
from rasa_core.channels.console import ConsoleInputChannel
from rasa_core.interpreter import RegexInterpreter
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.interpreter import RasaNLUInterpreter

from bot_server_channel import BotServerInputChannel

logger = logging.getLogger(__name__)

def train_dialogue(domain_file = 'domain.yml',
                    model_path = './models/dialogue',
                    training_data_file = './data/stories.md'):
                    
    agent = Agent(domain_file, policies = [MemoizationPolicy(),KerasPolicy()])#MemoizationPolicy(),
    
    agent.train(
                training_data_file,
                max_history = 3,
                epochs = 300,
                batch_size = 15,
                validation_split = 0.0,
                augmentation_factor = 0)
                
    agent.persist(model_path)
    return agent
    
def run_bot(serve_forever=True):
    interpreter = RasaNLUInterpreter('./nlu')
    agent = Agent.load('./models/dialogue', interpreter = interpreter)

    channel = BotServerInputChannel(agent)
    agent.handle_channel(channel)


    
if __name__ == '__main__':
   
    run_bot()
    

I am a docker newbie and so it seems simple to start to just docker this and let the GUI outside? Would I just just docker this complete code as a python code? What would I have to do with the GUI then. In the GUI I have to give the host where NLU is listening to. So I just give this port inside the dockerfile?


(Datisto) #3

Hey,

I managed to docker my bot. But now I am confused about the ports.

I run the docker with:

docker run -p 4000:4000 mybot

In my docker toolbox the message comes that server started at 5002:

INFO:root:Started http server on port 5002
2018-08-29 18:39:50+0000 [-] Log opened.
2018-08-29 18:39:50+0000 [-] Site starting on 5002
2018-08-29 18:39:50+0000 [-] Starting factory <twisted.web.server.Site object at 0x7faaa3ac50b8>

Then I tried with the IP of the docker toolbox in my browser with http://192.168.99.100:5002/

But connection is refused.

What I have forget to think about?


(Datisto) #4

Do I have to give a port in my docker file? My file looks simple like that:

FROM rasa_core
COPY agents /app
WORKDIR /app
CMD ["python", "./bot.py"]

And this rasa_core file just installs rasa_core, rasa_nlu.


(Siva Kovvuru) #5

add EXPOSE portNumber to your Dockerfile

Previous working example (now broken due to Rasa Core updates) below: