Self-Hosting with Docker
Relevant source files
The following files were used as context for generating this wiki page:The Discord Live Translator can be self-hosted using Docker and Docker Compose, which is the recommended method for running a private instance of the bot. This approach encapsulates the main bot application and its dependent services into isolated containers, simplifying deployment and management. The system is composed of four main services: the bot itself, a speech-to-text (STT) service, a translation service, and a Redis database for session storage.
This document outlines the architecture of the Docker setup, the necessary configuration, and the steps required to deploy and manage the application. It covers both production and development environments as defined in the provided Docker Compose files.
Sources: README.md:19-21, docker-compose.prod.yml
Architecture
The self-hosted application runs as a multi-container setup orchestrated by Docker Compose. The architecture consists of a primary bot service that communicates with several backend services to perform its functions.
Sources: docker-compose.prod.yml:3-4
Service Overview
The following diagram illustrates the services and their dependencies as defined in the production Docker Compose file.
This diagram shows the four main services (bot, stt, libretranslate, redis) and the flow of communication between them. The bot service is the central component that interacts with Discord and orchestrates the other services.
Sources: docker-compose.prod.yml:5-29, src/processors/recognizeRecording.ts:10-16, src/processors/translate.ts:11-17
Service Details
The Docker environment is composed of four key services.
| Service | Image | Role |
|---|---|---|
bot | ghcr.io/wotschofsky/discord-live-translator | The main Discord bot application. It connects to Discord, handles slash commands, records audio, and orchestrates calls to the STT and translation services. |
stt | ghcr.io/wotschofsky/discord-live-translator/stt | A Rust-based speech-to-text service using the Whisper model. It receives WAV audio data and transcribes it to text. |
libretranslate | libretranslate/libretranslate:v1.3.11 | An open-source machine translation API. It translates text from a source language (English) to a target language. |
redis | redis:alpine | An in-memory data store used for persisting user settings and session data. |
Sources: docker-compose.prod.yml:5-29, stt/src/main.rs:8-15
Configuration
Configuration is managed primarily through a .env file in the project's root directory. This file is loaded by the Docker Compose services at runtime.
Sources: docker-compose.prod.yml:8, src/env.ts:5
Environment Variables
The following environment variables are used to configure the services. The bot service requires several variables to connect to Discord and its dependent services.
| Variable | Service(s) | Description | Required | Default |
|---|---|---|---|---|
BOT_TOKEN | bot | The token for your Discord bot application. | Yes | - |
CLIENT_ID | bot | The client ID of your Discord application. Optional, but needed for deploying commands. | No | - |
GUILD_ID | bot | If set, slash commands will be automatically re-deployed for this specific server on startup. | No | - |
REDIS_URL | bot | The connection URL for the Redis instance. | No | redis://redis:6379 (in Docker) |
STT_HOST | bot | The URL for the speech-to-text service. | Yes | http://stt:8000 (in Docker) |
TRANSLATION_HOST | bot | The URL for the translation service. | Yes | http://libretranslate:5000 (in Docker) |
MODEL_PATH | stt | The file path inside the stt container where the Whisper model is located. | Yes | - |
LT_LOAD_ONLY | libretranslate | A comma-separated list of language codes to load, e.g., de,en,es,fr,it. | No | - |
LOG_PATH | bot | An optional file path to write logs to. | No | - |
HEARTBEAT_URL | bot | An optional URL to send a heartbeat POST request to every minute. | No | - |
Sources: src/env.ts:8-22, docker-compose.prod.yml:9-12, stt/src/main.rs:10-12, docker-compose.prod.yml:23-24
An example .env file would look like this:
# .env
BOT_TOKEN=your_discord_bot_token_here
CLIENT_ID=your_discord_app_client_id_here
GUILD_ID=your_discord_server_id_here
Sources: README.md:24-25
Deployment
The deployment process involves setting up the configuration, starting the services with Docker Compose, and deploying the bot's slash commands.
Production Deployment
The production deployment uses pre-built images from ghcr.io and is optimized for stability.
The following flowchart outlines the production deployment steps:
This flow ensures all services are running and the necessary Discord slash commands are registered globally.
Sources: README.md:23-29, package.json:12
The pnpm run deploy command executes the src/deploy.ts script, which initializes the global slash commands required to interact with the bot.
// src/deploy.ts:4-7
if (!env.CLIENT_ID) {
throw new Error('CLIENT_ID is not set!');
}
initGlobalCommands(env.BOT_TOKEN, env.CLIENT_ID)
Sources: src/deploy.ts:4-7
Development Environment
A development setup is also available via docker-compose.dev.yml. This configuration differs from production in a few key ways:
- It builds the
botandsttservices from the local source code instead of pulling pre-built images. - It exposes ports for
stt(8000),libretranslate(5000), andredis(6379) to the host machine, allowing for direct interaction and debugging.
Sources: docker-compose.dev.yml:5-29
Summary
Self-hosting the Discord Live Translator with Docker provides a robust and manageable way to run a private instance of the bot. The architecture is modular, with distinct services for the bot logic, speech-to-text, translation, and data persistence. By configuring a simple .env file and using the provided Docker Compose files, users can quickly deploy the entire stack. The separation between production and development configurations allows for both stable deployment and flexible local development.