How to self host Libre Translate on docker compose

Unlike Lingva the proxy for google translate, Libre Translate uses Argos Translate which is an actual translate engine. It has it's own engine and it's own AI and API for translations so weather you are an application owner want free API or normal user want to escape the bubble of google translate, you came to the right application :)

It's easy to host it but before I start I will assume that: * You are running debian 11 * You already have a VPS: https://blog.esmailelbob.xyz/how-to-get-a-vps * Your linux distro is up-to-date (sudo apt update && sudo apt upgrade) * You have a domain name: https://blog.esmailelbob.xyz/how-to-get-a-domain-name * Have sudo access or root account * Already installed docker and docker-compose: https://blog.esmailelbob.xyz/how-to-install-docker-and-docker-compose * Already installed Nginx: https://blog.esmailelbob.xyz/how-to-install-and-configure-nginx-96yp * Already have a reverse proxy conf file: https://blog.esmailelbob.xyz/how-to-use-reverse-proxy-with-nginx * Already have certbot to issue cert: https://blog.esmailelbob.xyz/how-to-use-certbot-with-nginx-to-make-your-website-get

System Requirements

RAM: 4GB

Changes in DNS (domain side)

You really do not need to add any dns entries except if you want to create subdomain for this container then you go in your domain's dns panel and add either CNAME entry that looks like subdomain.domain.com and make it's target the root domain domain.com or A entry with subdoamin.domain.com and make it's target the IP of your VPS

Libre translate docker-compose file

We need a docker-compose.yml file so we can start Libre translate, for me I use this file:

version: "3"

services:
  libretranslate:
    container_name: libretranslate
    #build: .
    image: libretranslate/libretranslate
    restart: unless-stopped
    ports:
      - 127.0.0.1:5550:5000
    ## Uncomment above command and define your args if necessary
    command: --frontend-language-source en --frontend-language-target ar

Optional stuff to change: 127.0.0.1:5550: The IP and port number for Libre translate (so we can use it later for nginx to reverse proxy it) command: Is configuration for Libre translate, to know more args or commands to add in libre translate, please visit: https://github.com/LibreTranslate/LibreTranslate#arguments

Spin it up!

Now after we done editing, and everything is cool. We need to run our container so just run:

docker-compose up -d

the -d option does not let docker post logs of running application but if you want to see logs you can run:

sudo docker-compose logs -f -t

To check if there any weird behaviors or errors

Nginx

Now after we make sure it's running well. We need to serve it over the internet (called reverse proxy) so without much talk, here is our server block for Libre translate:

server {
        listen [::]:80;
        listen 80;
       
        server_name [domain name] ;

       location / {
               include /etc/nginx/reverse-proxy.conf;
               proxy_pass http://127.0.0.1:5550/;
       }
}

server_name: Change this to match domain name of libre translate include: is our reverse proxy file proxy_pass: the IP and port of our running docker image

After this you should be up and running for Libre translate! :) just do not forget to run certbot --nginx to make it secure with https://

Update it

Of course after some time the image will be outdated and you need to update and what I love about docker that it's easy to update, really just to do it run:

docker-compose down && docker-compose pull && docker-compose up -d

What it does is: 1) Stops the container, 2) Pull last update (download last update) and 3) Re-run the container back!

Firewall

If you use firewall (ufw for example) you really do not need any ports other than 443 and 80 as we use nginx reverse proxy

#howto #selfhost #docker