How to Install and Run LibreTranslate with Docker: A Step-by-Step Guide

LibreTranslate is an open-source translation API that is gaining popularity for its ease of use and powerful features. In this blog post, we’ll guide you through the process of installing and running LibreTranslate using Docker. We’ll also show you how to set up API keys for enhanced security and usability.

Prerequisites

Before we start, make sure you have Docker installed on your system. If not, visit the official Docker website for installation instructions.

Step 1: Setting Up Docker compose File

First, create a compose file for Docker using any text editor. This file contains all the necessary configurations to run LibreTranslate. Here’s a sample stack file you can use:

version: '3'
services:
  libretranslate:
    image: libretranslate/libretranslate
    ports:
      - "5000:5000"
    environment:
      - LT_API_KEYS=true

Save this file as docker-compose.yml in a directory of your choice.

Step 2: Running LibreTranslate

Navigate to the directory where you saved docker-compose.yml and run the following command to start LibreTranslate:

docker-compose up -d

This command will download the necessary images and start the LibreTranslate service.

Step 3: Adding API Keys

For added security and control, LibreTranslate allows you to set up API keys. To enable API key functionality, we’ve already set LT_API_KEYS=true in the stack file.

Accessing Container Console

To add an API key, first, access the container’s console. Find the container ID using:

docker ps

Then, execute:

docker exec -it [container_id] /bin/bash

Replace [container_id] with the actual ID of your LibreTranslate container.

Adding and Listing API Keys

Inside the container’s console, add a new API key by typing:

./vene/bin/ltmanage keys add 120

This command will add a new API key. To list all existing API keys, simply execute:

./vene/bin/ltmanage keys

Important Considerations

  • Startup Delay: After starting the LibreTranslate service, there might be a delay before the web console becomes available. This delay is normal as the service is initializing.
  • Database Creation: The db/api_keys.db file is created during this initialization period. It’s crucial to wait for this process to complete before attempting to add API keys.
  • Checking Readiness: A good indication that the service is ready is when the web console loads successfully. Once you can access the web console, it’s safe to proceed with adding API keys.

Conclusion

LibreTranslate with Docker offers a convenient and powerful way to deploy your own translation service. By following the steps outlined above, you can have a running instance of LibreTranslate with enhanced security through the use of API keys. Remember to be patient during the initial startup and database creation process. Happy translating!


Feel free to use and modify this guide according to your needs. If you encounter any issues or have questions, the LibreTranslate community is always there to help.

Leave a Reply

Your email address will not be published. Required fields are marked *