{"id":59,"date":"2024-01-25T15:06:59","date_gmt":"2024-01-25T15:06:59","guid":{"rendered":"https:\/\/thevadasan.com\/?p=59"},"modified":"2024-01-25T15:07:00","modified_gmt":"2024-01-25T15:07:00","slug":"how-to-install-and-run-libretranslate-with-docker-a-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/thevadasan.com\/?p=59","title":{"rendered":"How to Install and Run LibreTranslate with Docker: A Step-by-Step Guide"},"content":{"rendered":"\n<p>LibreTranslate is an open-source translation API that is gaining popularity for its ease of use and powerful features. In this blog post, we&#8217;ll guide you through the process of installing and running LibreTranslate using Docker. We&#8217;ll also show you how to set up API keys for enhanced security and usability.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before we start, make sure you have Docker installed on your system. If not, visit the <a href=\"https:\/\/www.docker.com\/\">official Docker website<\/a> for installation instructions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Setting Up Docker compose File<\/h2>\n\n\n\n<p>First, create a compose file for Docker using any text editor. This file contains all the necessary configurations to run LibreTranslate. Here&#8217;s a sample stack file you can use:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nversion: '3'\nservices:\n  libretranslate:\n    image: libretranslate\/libretranslate\n    ports:\n      - &quot;5000:5000&quot;\n    environment:\n      - LT_API_KEYS=true\n<\/pre><\/div>\n\n\n<p>Save this file as <code>docker-compose.yml<\/code> in a directory of your choice.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Running LibreTranslate<\/h2>\n\n\n\n<p>Navigate to the directory where you saved <code>docker-compose.yml<\/code> and run the following command to start LibreTranslate:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndocker-compose up -d\n<\/pre><\/div>\n\n\n<p>This command will download the necessary images and start the LibreTranslate service.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Adding API Keys<\/h2>\n\n\n\n<p>For added security and control, LibreTranslate allows you to set up API keys. To enable API key functionality, we&#8217;ve already set <code>LT_API_KEYS=true<\/code> in the stack file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing Container Console<\/h3>\n\n\n\n<p>To add an API key, first, access the container&#8217;s console. Find the container ID using:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndocker ps\n<\/pre><\/div>\n\n\n<p>Then, execute:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndocker exec -it &#91;container_id] \/bin\/bash\n<\/pre><\/div>\n\n\n<p>Replace <code>[container_id]<\/code> with the actual ID of your LibreTranslate container.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding and Listing API Keys<\/h3>\n\n\n\n<p>Inside the container&#8217;s console, add a new API key by typing:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n.\/vene\/bin\/ltmanage keys add 120\n<\/pre><\/div>\n\n\n<p>This command will add a new API key. To list all existing API keys, simply execute:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.\/vene\/bin\/ltmanage keys\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Important Considerations<\/h2>\n\n\n\n<ul>\n<li><strong>Startup Delay:<\/strong> 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.<\/li>\n\n\n\n<li><strong>Database Creation:<\/strong> The <code>db\/api_keys.db<\/code> file is created during this initialization period. It&#8217;s crucial to wait for this process to complete before attempting to add API keys.<\/li>\n\n\n\n<li><strong>Checking Readiness:<\/strong> A good indication that the service is ready is when the web console loads successfully. Once you can access the web console, it&#8217;s safe to proceed with adding API keys.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>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!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LibreTranslate is an open-source translation API that is gaining popularity for its ease of use and powerful features. In this blog post, we&#8217;ll guide you through the process of installing and running LibreTranslate using Docker. We&#8217;ll also show you how to set up API keys for enhanced security and usability. Prerequisites Before we start, make [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":62,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17,18],"tags":[],"_links":{"self":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts\/59"}],"collection":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=59"}],"version-history":[{"count":3,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":63,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/posts\/59\/revisions\/63"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=\/wp\/v2\/media\/62"}],"wp:attachment":[{"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thevadasan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}