Articles

How to install Librechat AI with Docker and Traefik

Librechat.ai is an open source AI chat platform that you can host yourself. In this tutorial, we will install Librechat AI using Docker and Traefik.

I’ve had some hoops to jump through to get everything working, so I thought I’d share the steps I took to get it up and running.

This guide assumes you are using an external network called web to route all your traffic through Traefik.

#Step 1: Follow the official installation guide

The official installation guide can be found here. Follow the guide to set up the required environment variables and start the Docker containers.

#Adjust the docker-compose.override.yml file

1version: '3.4'
2 
3services:
4 api:
5 labels:
6 - 'traefik.enable=true'
7 - 'traefik.http.routers.librechat.rule=Host(`your.domain.example.com`)'
8 - 'traefik.http.routers.librechat.tls=true'
9 - 'traefik.http.routers.librechat.tls.certresolver=lets-encrypt'
10 - 'traefik.http.services.librechat.loadbalancer.server.port=3080'
11 networks:
12 - web
13 - librechat_default
14 volumes:
15 - ./librechat.yaml:/app/librechat.yaml
16 
17networks:
18 web:
19 external: true
20 librechat_default:
21 external: true

#Adjust the .env file

To get the keys you may use the following script, place it in a file and run the file with node file.js:

1const crypto = require('crypto')
2 
3// Generate a 32-byte key (64 characters in hex)
4const key = crypto.randomBytes(32).toString('hex')
5 
6// Generate a 16-byte IV (32 characters in hex)
7const iv = crypto.randomBytes(16).toString('hex')
8 
9// Generate a 32-byte key (64 characters in hex)
10const jwt = crypto.randomBytes(32).toString('hex')
11 
12// Generate a 32-byte key (64 characters in hex)
13const jwt2 = crypto.randomBytes(32).toString('hex')
14 
15console.log(`CREDS_KEY=${key}`)
16console.log(`CREDS_IV=${iv}`)
17console.log(`JWT_SECRET=${jwt}`)
18console.log(`JWT_REFRESH_SECRET=${jwt2}`)

After that you can adjust the .env file:

1HOST=localhost
2PORT=3080
3 
4DOMAIN_CLIENT=https://your.domain.example.com
5DOMAIN_SERVER=https://your.domain.example.com
6 
7OPENAI_API_KEY=your-key
8ASSISTANTS_API_KEY=your-key
9APP_TITLE="a fancy title"
10 
11CREDS_KEY=f151369e25852102edfa394fd034df5ac492c2a0028acaa51260402916488c65
12CREDS_IV=13272260bd313fd2d032ddcd70b75769
13JWT_SECRET=4d10e5b41de2d88a819b0e4b8600d1834c25356a44323cfb1bd3a8e839688b04
14JWT_REFRESH_SECRET=4f73e40aadf694f829b9980d0224cd14783d791f5744627af9d94ed71dc34943
15 
16ALLOW_REGISTRATION=true

#Starting the containers

After adjusting the files, you can start the containers with the following command:

1docker-compose up -d

That should be it! You should now be able to access Librechat AI at https://your.domain.example.com.


You might find these related articles helpful or interesting, make sure to check them out!

I hope you found this article useful! 😊.