# 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).

The recommended deployment methods described below make it easy to share your assistant with test users via the [share your assistant feature in Rasa X](/content/docs/rasa-x/user-guide/enable-workflows#conversations-with-test-users/index.html). Then, when you’re ready to make your assistant available via one or more [Messaging and Voice Channels](https://legacy-docs-v1.rasa.com/1.7.4/user-guide/messaging-and-voice-channels/#messaging-and-voice-channels), you can easily add them to your existing deployment set up.

## 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](/content/docs/rasa-x/installation-and-setup/openshift-kubernetes/index.html).
- Custom: Read the docs [here](/content/docs/rasa-x/installation-and-setup/openshift-kubernetes/index.html) 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](/content/docs/rasa-x/installation-and-setup/docker-compose-script/index.html).
- Custom: Read the docs [here](/content/docs/rasa-x/installation-and-setup/docker-compose-manual/index.html).

## Rasa-Only Deployment with Docker Compose
It is also possible to deploy a Rasa assistant using Docker Compose without Rasa X.

- [Installing Docker](https://legacy-docs-v1.rasa.com/1.7.4/user-guide/how-to-deploy/#installing-docker)
- [Building an Assistant with Rasa and Docker](https://legacy-docs-v1.rasa.com/1.7.4/user-guide/how-to-deploy/#building-an-assistant-with-rasa-and-docker)
- [Customizing your Model](https://legacy-docs-v1.rasa.com/1.7.4/user-guide/how-to-deploy/#customizing-your-model)
- [Running the Rasa Server](https://legacy-docs-v1.rasa.com/1.7.4/user-guide/how-to-deploy/#running-the-rasa-server)
- [Using Docker Compose to Run Multiple Services](https://legacy-docs-v1.rasa.com/1.7.4/user-guide/how-to-deploy/#using-docker-compose-to-run-multiple-services)
- [Adding Custom Actions](https://legacy-docs-v1.rasa.com/1.7.4/user-guide/how-to-deploy/#adding-custom-actions)
- [Adding a Custom Tracker Store](https://legacy-docs-v1.rasa.com/1.7.4/user-guide/how-to-deploy/#adding-a-custom-tracker-store)

### Installing Docker
If you’re not sure if you have Docker installed, you can check by running:
```bash
docker -v && docker-compose -v
# Docker version 18.09.2, build 6247962
# docker-compose version 1.23.2, build 1110ad01
```

### Building an Assistant with Rasa and Docker
This section will cover the following:
- 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.4/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`. To initialize your project, run:
```bash
docker run -v $(pwd):/app rasa/rasa init --no-prompt
```
### Talking to Your Assistant
To talk to your newly-trained assistant, run this command:
```bash
docker run -it -v $(pwd):/app rasa/rasa shell
```
### 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. See [Choosing a Pipeline](https://legacy-docs-v1.rasa.com/1.7.4/nlu/choosing-a-pipeline/#choosing-a-pipeline) for more information about dependencies.

#### 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.

```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.4/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/).

### Adding Custom Actions
To create more sophisticated assistants, you will want to use [Custom Actions](https://legacy-docs-v1.rasa.com/1.7.4/core/actions/#custom-actions). Continuing the example from above, you might want to add an action which tells the user a joke to cheer them up.

#### Creating a Custom Action
Start by creating the custom actions in a directory `actions`:
```bash
mkdir actions
# Rasa SDK expects a python module.
# Therefore, make sure that you have this file in the directory.
touch actions/__init__.py
touch actions/actions.py
```

### 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.4/api/tracker-stores/#tracker-stores).

#### Using PostgreSQL as Tracker Store
Start by adding PostgreSQL to your docker-compose file:
```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
Start by adding MongoDB to your docker-compose file. You can then start all components with `docker-compose up`.
