These instructions are designed for someone starting from scratch for a Docker Installation on a remote Ubuntu server. You can skip to any point that is useful for you. There are probably more efficient/scalable ways, but this guide works really great for my personal use case.
There are many ways to go about this, but I will present to you the best and easiest methods I'm aware of. These configurations can vary based on your liking or needs.
Digital Ocean is a great option for deployment: you can benefit off a free 200 USD credit (for 60 days), and one of the cheapest tiers (6 USD/mo) will work for LibreChat in a low-stress, minimal-user environment. Should your resource needs increase, you can always upgrade very easily.
Digital Ocean is also my preferred choice for testing deployment, as it comes with useful resource monitoring and server access tools right out of the box.
Using the following Digital Ocean link will directly support the project by helping me cover deployment costs with credits!
You are free to use this credit as you wish!
Note: you will need a credit card or PayPal to sign up. I'm able to use a prepaid debit card through PayPal for my billing
- Part I: Starting from Zero
- Part II: Installing Docker & Other Dependencies
- Part III: Setup LibreChat
- Part IV: Updating LibreChat
The last sections are all optional configurations
1. Click here or on the banner above to get started on DigitalOcean
Once you're logged in, you will be greeted with a nice welcome screen.
a) Click on "Explore our control panel" or simply navigate to the Projects page
Server instances are called "droplets" in digitalocean, and they are organized under "Projects."
Adjust these settings based on your needs, as I'm selecting the bare minimum/cheapest options that will work.
- Choose Region/Datacenter: closest to you and your users
- Choose an image: Ubuntu 22.04 (LTS) x64
- Choose Size: Shared CPU, Basic Plan
- CPU options: Regular, 6 USD/mo option (0.009 USD/hour, 1 GB RAM / 1 CPU / 25 GB SSD / 1000 GB transfer)
- No additional storage
- Choose Authentication Method: Password option is easiest but up to you
- Alternatively, you can setup traditional SSH. The Hetzner guide has good instructions for this that can apply here
- Recommended: Add improved metrics monitoring and alerting (free)
- You might be able to get away with the $4/mo option by not selecting this, but not yet tested
- Finalize Details:
- Change the hostname to whatever you like, everything else I leave default (1 droplet, no tags)
- Finally, click "Create Droplet"
After creating the droplet, it will now spin up with a progress bar.
Once it's spun up, click on the droplet and click on the Console link on the right-hand side to start up the console.
Launching the Droplet console this way is the easiest method but you can also SSH if you set it up in the previous step.
To keep this guide simple, I will keep it easy and continue with the droplet console. Here is an official DigitalOcean guide for SSH if you are interested. As mentioned before, the Hetzner guide has good instructions for this that can apply here.
Note: you should remove the greater/less than signs anytime you see them in this guide
# example: adduser danny
adduser <yourusername>
# you will then be prompted for a password and user details
Once you are done, run the following command to elevate the user
# example: usermod -aG sudo danny
usermod -aG sudo <yourusername>
Make sure you have done this correctly by double-checking you have sudo permissions:
getent group sudo | cut -d: -f4
Switch to the new user
# example: su - danny
su - <yourusername>
It's highly recommended you setup a simple firewall for your setup.
Click on your droplet from the projects page again, and goto the Networking tab on the left-hand side under your ipv4:
Create a firewall, add your droplet to it, and add these inbound rules (will work for this guide, but configure as needed)
There are many ways to setup Docker on Debian systems. I'll walk you through the best and the recommended way based on this guide.
Note that the "Best" way for Ubuntu docker installation does not mean the "fastest" or the "easiest". It means, the best way to install it for long-term benefit (i.e. faster updates, security patches, etc.).
First, let's update our packages list and install the required docker dependencies.
sudo apt update
Then, use the following command to install the dependencies or pre-requisite packages.
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release
- Input "Y" for all [Y/n] (yes/no) terminal prompts throughout this entire guide.
- After the first [Y/n] prompt, you will get the first of a few purple screens asking to restart services.
- Each time this happens, you can safely press ENTER for the default, already selected options:
- If at any point your droplet console disconnects, do the following and then pick up where you left off:
- Access the console again as indicated above
- Switch to the user you created with
su - <yourusername>
While installing Docker Engine from Ubuntu repositories is easier, adding official docker repository gives you faster updates. Hence why this is the recommended method.
First, let us get the GPG key which is needed to connect to the Docker repository. To that, use the following command.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Next, add the repository to the sources list. While you can also add it manually, the command below will do it automatically for you.
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
The above command will automatically fill in your release code name (jammy for 22.04, focal for 20.04, and bionic for 18.04).
Finally, refresh your packages again.
sudo apt update
If you forget to add the GPG key, then the above step would fail with an error message. Otherwise, let's get on with installing Docker on Ubuntu.
What is the difference between docker.io and docker-ce?
docker.io is the docker package that is offered by some popular Linux distributions (e.g. Ubuntu/Debian). docker-ce on the other hand, is the docker package from official Docker repository. Typically docker-ce more up-to-date and preferred.
We will now install the docker-ce (and not docker.io package)
sudo apt install docker-ce
Purple screen means press ENTER. :)
Recommended: you should make sure the created user is added to the docker group for seamless use of commands:
sudo usermod -aG docker $USER
Now let's reboot the system to make sure all is well.
sudo reboot
After rebooting, if using the browser droplet console, you can click reload and wait to get back into the console.
Reminder: Any time you reboot with sudo reboot
, you should switch to the user you setup as before with su - <yourusername>
.
There are many ways to check if Docker is running on Ubuntu. One way is to use the following command:
sudo systemctl status docker
You should see an output that says active (running) for status.
Exit this log by pressing CTRL (or CMD) + C.
The version of docker-compose packaged with the Linux distribution is probably old and will not work for us.
Checking the releases on the Docker Compose GitHub, the last release is v2.20.2 (as of 8/9/23).
You will have to manually download and install it. But fear not, it is quite easy.
First, download the latest version of Docker Compose using the following command:
sudo curl -L https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
Next, make it executable using the following command:
sudo chmod +x /usr/local/bin/docker-compose
Docker Compose should now be installed on your Ubuntu system. Let's check to be sure.
docker-compose -v
# output should be: Docker Compose version v2.20.2
If you get a permission denied error, like I did, reboot/switch to your created user again, and run sudo chmod +x /usr/local/bin/docker-compose
again
Though not technically required, having git and npm will make installing/updating very simple:
sudo apt install git nodejs npm
Cue the matrix lines.
You can confirm these packages installed successfully with the following:
git --version
node -v
npm -v
Note: this will install some pretty old versions, for npm in particular. For the purposes of this guide, however, this is fine, but this is just a heads up in case you try other things with node in the droplet. Do look up a guide for getting the latest versions of the above as necessary.
Ok, now that you have set up the Droplet, you will now setup the app itself
From the droplet commandline (as your user, not root):
# clone down the repository
git clone https://github.com/danny-avila/LibreChat.git
# enter the project directory
cd LibreChat/
The default values are enough to get you started and running the app.
# Copies the example file as your global env file
cp .env.example .env
However, it's highly recommended you use environment variables for any sensitive credentials until we remove use of localStorage for passing credentials from the frontend
nano .env
# then, add your credentials
OPENAI_API_KEY=sk-yourKey
That's it!
For thorough configuration, however, you should edit your .env file as needed, and do read the comments in the file and the resources below.
# if editing the .env file
nano .env
This is one such env variable to be mindful of. This disables external signups, in case you would like to set it after you've created your account.
ALLOW_REGISTRATION=false
Resources:
# should already be running, but just to be safe
sudo systemctl start docker
# confirm docker is running
docker info
Now we can start the app container. For the first time, we'll use the full command and later we can use a shorthand command
sudo docker-compose -f ./deploy-compose.yml up -d
It's safe to close the terminal if you wish -- the docker app will continue to run.
Note: this is using a special compose file optimized for this deployed environment. If you would like more configuration here, you should inspect the deploy-compose.yml and Dockerfile.multi files to see how they are setup. We are not building the image in this environment since it's not enough RAM to properly do so. Instead, we pull the latest dev-api image of librechat, which is automatically built after each push to main.
If you are setting up a domain to be used with LibreChat, this compose file is using the nginx file located in client/nginx.conf. Instructions on this below in part V.
4. Once the app is running, you can access it at http://yourserverip
Go back to the DigitalOcean droplet page to get your server ip, copy it, and paste it into your browser!
I've made this step pretty painless, provided everything above was installed successfully and you haven't edited the git history.
Note: If you are working on an edited branch, with your own commits, for example, such as with edits to client/nginx.conf, you should inspect config/deployed-update.js to run some of the commands manually as you see fit. See part V for more on this.
Run the following for an automated update
npm run update:deployed
Stopping the docker container
npm run stop:deployed
This simply runs
docker-compose -f ./deploy-compose.yml down
Starting the docker container
npm run start:deployed
This simply runs
docker-compose -f ./deploy-compose.yml up -d
Check active docker containers
docker ps
In case you would like to edit the NGINX file for whatever reason, such as pointing your server to a custom domain, use the following:
# First, stop the active instance if running
npm run stop:deployed
# now you can safely edit
nano client/nginx.conf
I won't be walking you through custom domain setup or any other changes to NGINX, you can look into the Cloudflare setup guide to get you started with custom domains.
However, I will show you what to edit on the LibreChat side for a custom domain with this setup.
Since NGINX is being used as a proxy pass by default, I only edit the following:
# before
server_name localhost;
# after
server_name custom.domain.com;
Exit nano with
Note: this works because the deploy-compose.yml file is using NGINX by default, unlike the main docker-compose.yml file. As always, you can configure the compose files as you need.
Now commit these changes to a separate branch:
# create a new branch
# example: git checkout -b edit
git checkout -b <branchname>
# stage all file changes
git add .
To commit changes to a git branch, you will need to identify yourself on git. These can be fake values, but if you would like them to sync up with GitHub, should you push this branch to a forked repo of LibreChat, use your GitHub email
# these values will work if you don't care what they are
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
# Now you can commit the change
git commit -m "edited nginx.conf"
Updating on an edited branch will work a little differently now
npm run rebase:deployed
You should be all set!
⚠️ You will experience merge conflicts if you start significantly editing the branch and this is not recommended unless you know what you're doing
Note that any changes to the code in this environment won't be reflected because the compose file is pulling the docker images built automatically by GitHub
By default, this setup will pull the latest updates to the main branch of Librechat. If you would rather have the latest "stable" release, which is defined by the latest tags, you will need to edit deploy-compose.yml and commit your changes exactly as above in Part V.
Let's edit deploy-compose.yml
:
nano deploy-compose.yml
Change librechat-dev-api
to librechat-api
:
image: ghcr.io/danny-avila/librechat-api:latest
Stage and commit as in Part V, and you're all set!