Skip to main content

Dockerized Deployment of LibreChat

The LibreChat project is built around Docker making deployment a breeze in a variety of environments. In the last section, we created a DigitalOcean Droplet running Ubuntu 22.04. In this section, we will install Docker on the Droplet and deploy the LibreChat project using Docker.

The LibreChat Docker deployment guide walks through the process indicating explicitly that the installation is the "best" and may not be the quickest. The reason for this claim is that it's meant to make long-term maintenance easier in terms of updates and security patches etc.

Docker on Ubuntu DigitalOcean Droplet​

Step 1: Install Docker + Dependencies​

  1. SSH into your DigitalOcean Droplet using the following command:

    ssh <yourusername>@<your-droplet-ip>
    note

    Use the non-root user you created in the previous section. If you can only SSH into the Droplet with the root user, you can switch to your non-root user with su - <yourusername>.

  2. Update the package list and install the required dependencies:

    sudo apt update
    sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release

    This will install a number of packages:

    • apt-transport-https - allows the use of repositories accessed via the HTTP Secure protocol (HTTPS)
    • ca-certificates - allows the system to check the authenticity of SSL certificates
    • curl - a command-line tool for transferring data with URLs
    • software-properties-common - provides an abstraction of the used apt repositories and allows for easy management of software sources
    • gnupg - GNU Privacy Guard, a complete and free implementation of the OpenPGP standard as defined by RFC4880 (also known as PGP)
    • lsb-release - provides information about the Linux distribution you are using to help with package management

Step 2: Add Docker Repository​

  1. Add the Docker GPG key to your system:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  2. Add the repository to the source list

    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
  3. Refresh your packges

    sudo apt update

Step 3: Install Docker​

  1. Install Docker

    sudo apt install docker-ce docker-ce-cli containerd.io

    The LibreChat guide suggests installing the docker-ce package, which is the community edition of Docker. This is the recommended package for our purpose. They note that many Linux distributions have docker-io packages in their repositories, but the Docker repository is the best place to get the latest version.

    warning

    When I performed these steps I got a message about a New Kernel being available and that I should reboot the server. I did this and then continued with the installation. I selected OK and then another meassage appeared about the some services needing to be restarted. I selected OK again and the services restarted.

  2. Ensure your user has permissions to run Docker commands:

    sudo usermod -aG docker $USER
  3. Reboot the server

    sudo reboot
  4. Your SSH session will be disconnected. Wait a few moments and then SSH back into the server.

    ssh <yourusername>@<your-droplet-ip>
  5. Change users to your non-root user:

    su - <yourusername>
  6. Verify that Docker is installed and running:

    sudo systemctl status docker

    You should see output indicating that Docker is active and running:

    Docker Active and Running

Step 4: Install Docker Compose​

The LibreChat docker guide inidcates that the version of Docker Compose available in the Ubuntu repositories may not be the latest version. They recommend installing the latest version from the Docker GitHub repository.

  1. Download the latest version of Docker Compose:

    sudo curl -L https://github.com/docker/compose/releases/download/v2.26.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

    Docker Compose Install

  2. Apply executable permissions to the binary:

     sudo chmod +x /usr/local/bin/docker-compose
  3. Verify that Docker Compose is installed:

    docker-compose --version

    You should see output indicating the version of Docker Compose that you installed:

Step 5 - More Dependencies: Git & NPM​

If you've browsed through the LibreChat documenations, you may have noticed that it is a very active project. This means that there are frequent updates and changes. To ensure that you have the latest version of the project, you will need to install Git and NPM which will make updating the app easier.

  1. Install git, nodejs and npm:

    sudo apt install git nodejs npm

    This will install the latest versions of Git, Node.js, and NPM on your server so be patient as it may take a few moments. Note that the packages are pretty darn old. You can check the versions by running:

     git --version
    node --version
    npm --version

Step 6: Update Git, Node.js, and NPM (Optional)​

Git

  1. Add the Git PPA:

    sudo add-apt-repository ppa:git-core/ppa

    This will output a description that tells us we are on track and where we want to be: "The most current stable version of Git for Ubuntu"

  2. Make sure to update the package list:

   sudo apt update
  1. Install the latest stable version of Git:
sudo apt install git
git --version

Node.js and NPM

  1. Add the NodeSource repository:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

  1. Install Node.js and NPM:

    sudo apt install -y nodejs
    warning

    You may get an error on the nodejs install related to libnode-dev using a file that can't be overritten by the new package. If you do, you can remove the libnode-dev package using the following steps:

    1. Remove the conflicting libnode-dev package:

      sudo apt remove libnode-dev
    2. Fix broken package dependencies:

      sudo apt --fix-broken install
    3. Reinstall Node.js and NPM:

      sudo apt install -y nodejs

    If your installation was successful you should see the following output. If not, ensure you've removed the older conflicting package and fixed the broken dependencies.

    Node.js and NPM Install

  2. Verify the installation:

    node --version
    npm --version

    You should see output indicating the versions of Node.js and NPM that you installed. Yours should be at least as recent as the versions shown below:

    Node.js and NPM Versions

The Ubuntu Droplet is now prepped and ready to install the app. Here is a recap of the steps we've taken:

  • Created a DigitalOcean Droplet running Ubuntu 22.04
  • Updated the package list and installed required dependencies
  • Added the Docker repository to the source list
  • Installed Docker and Docker Compose
  • Installed Git, Node.js, and NPM
  • Updated Git, Node.js, and NPM (optional)

Jump over to the next section to deploy the LibreChat app using Docker.