> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fonoster.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy with Docker

> Self-hosting with Docker and Docker Compose.

Docker is the easiest way to deploy a self-hosted instance of Fonoster. This guide will walk you through deploying the Fonoster services using Docker and Docker Compose.

## Prerequisites

The only prerequisite for Fonoster is to have [Docker](https://docs.docker.com/get-docker/) installed on the host machine.

## Step-by-step installation

<Steps>
  <Step title="Prepare the environment">
    Follow the next few steps to prepare the environment:

    <AccordionGroup>
      <Accordion title="Create a new directory">
        Create a new directory in your preferred location and change it. The root directory we will use in the guide is `fonoster.`

        ```bash theme={"system"}
        mkdir -p fonoster/config
        cd fonoster
        ```
      </Accordion>

      <Accordion title="Download the example configuration">
        Copy the `.env.example` from the repository to the current directory and rename it to `.env.` This file contains all the environment variables that the services need to run.

        You can use the following commands to copy all the necessary files:

        ```bash theme={"system"}
        curl -o .env https://raw.githubusercontent.com/fonoster/fonoster/master/.env.example
        curl -o ./compose.yaml https://raw.githubusercontent.com/fonoster/fonoster/master/compose.yaml
        curl -o ./config/integrations.json https://raw.githubusercontent.com/fonoster/fonoster/master/config/integrations.example.json
        curl -o ./config/envoy.yaml https://raw.githubusercontent.com/fonoster/fonoster/master/config/envoy.yaml
        ```
      </Accordion>

      <Accordion title="Update the configuration">
        Then, open the `.env` file with your favorite editor and update the following variables:

        * `ASTERISK_SIPPROXY_HOST`: Set this variable to the IP address of the host machine.

        * `ROUTR_EXTERNAL_ADDRS`: Set this variable to the IP address of the host machine.

        * `ROUTR_RTPENGINE_HOST`: Set this variable to the IP address of the host machine.

        <Note>
          The [integrations.json](https://github.com/fonoster/fonoster/blob/main/config/integrations.example.json) file contains the credentials for the integrations (stt, tts, etc). You must update this file with the correct credentials for the integrations you want to use.
        </Note>

        <Warning>
          In addition to the previous variables, you should update all the secrets and ensure the `.env` file is safely stored.
        </Warning>
      </Accordion>
    </AccordionGroup>
  </Step>

  <Step title="Generate keys">
    Next, generate a set of public and private keys for the server. You can use the following command to generate the keys:

    ```bash theme={"system"}
    mkdir -p config/keys
    openssl genpkey -algorithm rsa -out config/keys/private.pem -pkeyopt rsa_keygen_bits:2048
    openssl rsa -pubout -in config/keys/private.pem -out config/keys/public.pem
    chmod 644 config/keys/*
    ```
  </Step>

  <Step title="Confirm the directory structure">
    Your directory structure should look like this:

    ```bash theme={"system"}
    .
    ├── .env
    ├── compose.yaml
    └── config
        ├── envoy.yaml
        ├── integrations.json
        └── keys
            ├── private.pem
            └── public.pem

    3 directories, 6 files
    ```

    If it looks different, go back and review your steps.
  </Step>

  <Step title="Start the server">
    Finally, run the following command to start the application:

    ```bash theme={"system"}
    docker compose up -d
    ```

    After a few moments, you can interact with Fonoster using the API or SDK.
  </Step>
</Steps>

<CardGroup cols={2}>
  <Card title="SDK" icon="code" href="https://www.npmjs.com/package/@fonoster/sdk">
    SDK documentation at NPM.
  </Card>

  <Card title="Command-Line" icon="square-terminal" href="https://www.npmjs.com/package/@fonoster/ctl">
    Command-line documentation at NPM.
  </Card>
</CardGroup>
