In order to use this guide you need a remote computer or VM deployed. While you can use this guide with a local installation, keep in mind that it was originally written for cloud deployment.
> ⚠️ This guide was originally designed for [Digital Ocean](./digitalocean.md), so you may have to modify the instruction for other platforms, but the main idea remains unchanged.
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](https://www.smarthomebeginner.com/install-docker-on-ubuntu-22-04/).
> 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.).
### **1. Update and Install Docker Dependencies**
First, let's update our packages list and install the required docker dependencies.
```bash
sudo apt update
```
Then, use the following command to install the dependencies or pre-requisite packages.
- 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>`
### **2. Add Docker Repository to APT Sources**
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.
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.
```bash
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.
### **3. Install Docker**
> 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)
```bash
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:
```bash
sudo usermod -aG docker $USER
```
Now let's reboot the system to make sure all is well.
```bash
sudo reboot
```
After rebooting, if using the browser droplet console, you can click reload and wait to get back into the console.
Next, make it executable using the following command:
```bash
sudo chmod +x /usr/local/bin/docker-compose
```
Docker Compose should now be installed on your Ubuntu system. Let's check to be sure.
```bash
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
### **6. As part of this guide, I will recommend you have git and npm installed:**
Though not technically required, having git and npm will make installing/updating very simple:
```bash
sudo apt install git nodejs npm
```
Cue the matrix lines.
You can confirm these packages installed successfully with the following:
> 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**
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`**
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
```bash
npm run update:deployed
```
**Stopping the docker container**
```bash
npm run stop:deployed
```
> This simply runs `docker-compose -f ./deploy-compose.yml down`
**Starting the docker container**
```bash
npm run start:deployed
```
> This simply runs `docker-compose -f ./deploy-compose.yml up -d`
I won't be walking you through custom domain setup or any other changes to NGINX, you can look into the [Cloudflare guide](./cloudflare.md) or the [NGINX guide](./nginx.md) 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:
```shell
# 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:
```bash
# 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
```bash
# these values will work if you don't care what they are
git config --global user.email "you@example.com"
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
```bash
npm run rebase:deployed
```
You should be all set!
> :warning: 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](https://github.com/danny-avila/LibreChat/releases), you will need to edit deploy-compose.yml and commit your changes exactly as above in Part V. Be aware that you won't benefit from the latest feature as soon as they come if you do so.
Stage and commit as in Part V, and you're all set!
---
### Note: If you're still having trouble, before creating a new issue, please search for similar ones on our [#issues thread on our discord](https://discord.librechat.ai) or our [troubleshooting discussion](https://github.com/danny-avila/LibreChat/discussions/categories/troubleshooting) on our Discussions page. If you don't find a relevant issue, feel free to create a new one and provide as much detail as possible.