These docs are for version 1.x of Rasa Open Source.

## Deploying your Rasa Assistant

This page explains when and how to deploy an assistant built with Rasa. It will allow you to make your assistant available to users and set you up with a production-ready environment.

- **When to deploy your assistant**: The best time to deploy your assistant and make it available to test users is once it can handle the most important happy paths or is what we call a [minimum viable assistant](/content/docs/rasa/glossary/index.html).

- **Recommended Deployment Methods**: The recommended way to deploy an assistant is using either the Docker Compose or Kubernetes/Openshift options we support. Both deploy Rasa X and your assistant. They are the easiest ways to deploy your assistant, allow you to use Rasa X to view conversations and turn them into training data, and are production-ready.

### Kubernetes/Openshift

Kubernetes/Openshift is the best option if you need a scalable architecture. It’s straightforward to deploy if you use the helm charts we provide. However, you can also customize the Helm charts if you have specific requirements.

> - Default: Read the docs [here](https://legacy-docs-v1.rasa.com/1.7.1/rasa-x/docs/installation-and-setup/openshift-kubernetes/).
> - Custom: Read the docs [here](https://legacy-docs-v1.rasa.com/1.7.1/rasa-x/docs/installation-and-setup/openshift-kubernetes/) and customize the [open source Helm charts](https://github.com/RasaHQ/rasa-x-helm).

### Docker Compose

> - Default: Watching this [video](https://www.youtube.com/watch?v=IUYdwy8HPVc) or read the docs [here](https://legacy-docs-v1.rasa.com/1.7.1/rasa-x/docs/installation-and-setup/docker-compose-script/).
> - Custom: Read the docs [here](https://legacy-docs-v1.rasa.com/1.7.1/rasa-x/docs/installation-and-setup/docker-compose-manual/).

### Rasa-Only Deployment with Docker Compose

It is also possible to deploy a Rasa assistant using Docker Compose without Rasa X.

- **Installing Docker**: If you’re not sure if you have Docker installed, you can check by running:
  
  ```
  docker -v && docker-compose -v
  ```

- **Building an Assistant with Rasa and Docker**: This section will cover:
  - Setting up your Rasa project and training an initial model
  - Talking to your AI assistant via Docker
  - Choosing a Docker image tag
  - Training your Rasa models using Docker
  - Talking to your assistant using Docker
  - Running a Rasa server with Docker

#### Setup

Just like in the [tutorial](https://legacy-docs-v1.rasa.com/1.7.1/user-guide/rasa-tutorial/#rasa-tutorial), you’ll use the `rasa init` command to create a project. The only difference is that you’ll be running Rasa inside a Docker container, using the image `rasa/rasa`.

```bash
docker run -v $(pwd):/app rasa/rasa init --no-prompt
```

What does this command mean?

- `-v $(pwd):/app` mounts your current working directory to the working directory in the Docker container. This means that files you create on your computer will be visible inside the container, and files created in the container will get synced back to your computer.
- `rasa/rasa` is the name of the docker image to run.

Running this command will produce a lot of output. What happens is:

- a Rasa project is created
- an initial model is trained using the project’s training data.

To check that the command completed correctly, look at the contents of your working directory:

```bash
ls -1
```

The initial project files should all be there, as well as a `models` directory that contains your trained model.

Note: By default Docker runs containers as `root` user. Hence, all files created by these containers will be owned by `root`. See the documentation of docker and docker-compose if you want to run the containers with a different user.

#### Talking to Your Assistant

To talk to your newly-trained assistant, run this command:

```bash
docker run -it -v $(pwd):/app rasa/rasa shell
```

This will start a shell where you can chat to your assistant.

### Customizing your Model

#### Choosing a Tag

To keep images as small as possible, we publish different tags of the `rasa/rasa` image with different dependencies installed. All tags start with a version – the `latest` tag corresponds to the current master build. The tags are:

- `{version}`
- `{version}-spacy-en`
- `{version}-spacy-de`
- `{version}-mitie-en`
- `{version}-full`

### Training a Custom Rasa Model with Docker

Edit the `config.yml` file to use the pipeline you want, and place your NLU and Core data into the `data/` directory. Now you can train your Rasa model by running:

```bash
docker run \
  -v $(pwd):/app \
  rasa/rasa:latest-full \
  train \
    --domain domain.yml \
    --data data \
    --out models
```

### Running the Rasa Server

To run your AI assistant in production, configure your required [Messaging and Voice Channels](https://legacy-docs-v1.rasa.com/1.7.1/user-guide/messaging-and-voice-channels/#messaging-and-voice-channels) in `credentials.yml`. If this file does not exist, create it using:

```bash
touch credentials.yml
```

Then edit it according to your connected channels. After, run the trained model with:

```bash
docker run \
  -v $(pwd)/models:/app/models \
  rasa/rasa:latest-full \
  run
```

### Using Docker Compose to Run Multiple Services

To run Rasa together with other services, such as a server for custom actions, it is recommended to use [Docker Compose](https://docs.docker.com/compose/).

Start by creating a file called `docker-compose.yml`:

```bash
touch docker-compose.yml
```

Add the following content to the file:

```yaml
version: '3.0'
services:
  rasa:
    image: rasa/rasa:latest-full
    ports:
      - 5005:5005
    volumes:
      - ./:/app
    command:
      - run
```

### Adding Custom Actions

To create more sophisticated assistants, you will want to use [Custom Actions](https://legacy-docs-v1.rasa.com/1.7.1/core/actions/#custom-actions).

#### Creating a Custom Action

Start by creating the custom actions in a directory `actions`:

```bash
mkdir actions
touch actions/__init__.py
touch actions/actions.py
```

Then build a custom action using the Rasa SDK, e.g.:

```python
import requests
import json
from rasa_sdk import Action

class ActionJoke(Action):
  def name(self):
    return "action_joke"

def run(self, dispatcher, tracker, domain):
    request = requests.get('http://api.icndb.com/jokes/random').json()  # make an api call
    joke = request['value']['joke']  # extract a joke from returned json response
    dispatcher.utter_message(text=joke)  # send the message back to the user
    return []
```

Then add the custom action in your stories and your domain file.

#### Adding the Action Server

The custom actions are run by the action server. To spin it up together with the Rasa instance, add a service `action_server` to the `docker-compose.yml`:

```yaml
version: '3.0'
services:
  rasa:
    image: rasa/rasa:latest-full
    ports:
      - 5005:5005
    volumes:
      - ./:/app
    command:
      - run
  action_server:
    image: rasa/rasa-sdk:latest
    volumes:
      - ./actions:/app/actions
```

### Adding Custom Dependencies

If your custom action has additional dependencies of systems or Python libraries, you can add these by extending the official image.

### Adding a Custom Tracker Store

By default, all conversations are saved in memory. This means that all conversations are lost as soon as you restart the Rasa server. If you want to persist your conversations, you can use a different [Tracker Store](https://legacy-docs-v1.rasa.com/1.7.1/api/tracker-stores/#tracker-stores).

#### Using PostgreSQL as Tracker Store

```yaml
postgres:
  image: postgres:latest
```

Then add PostgreSQL to the `tracker_store` section of your endpoint configuration `config/endpoints.yml`:

```yaml
tracker_store:
  type: sql
  dialect: "postgresql"
  url: postgres
  db: rasa
```

#### Using MongoDB as Tracker Store

```yaml
mongo:
  image: mongo
  environment:
    MONGO_INITDB_ROOT_USERNAME: rasa
    MONGO_INITDB_ROOT_PASSWORD: example
```

Then add the MongoDB to the `tracker_store` section of your endpoints configuration `endpoints.yml`:

```yaml
tracker_store:
  type: mongod
  url: mongodb://mongo:27017
  username: rasa
  password: example
```

#### Using Redis as Tracker Store

```yaml
redis:
  image: redis:latest
```

Then add Redis to the `tracker_store` section of your endpoint configuration `endpoints.yml`:

```yaml
tracker_store:
  type: redis
  url: redis
```

#### Using a Custom Tracker Store Implementation

If you have a custom implementation of a tracker store you have two options to add this store to Rasa:

> - extending the Rasa image
> - mounting it as volume

Then add the required configuration to your endpoint configuration `endpoints.yml` as it is described in [Tracker Stores](https://legacy-docs-v1.rasa.com/1.7.1/api/tracker-stores/#tracker-stores). If you want the tracker store component (e.g. a certain database) to be part of your Docker Compose file, add a corresponding service and configuration there.
