-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add podman installation instructions. Update dockerfile to stub env (#…
…819) * Added podman container installation docs. Updated dockerfile to stub env file if not present in source * Fix typos
- Loading branch information
Showing
3 changed files
with
229 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
|
||
# Container installation guide | ||
|
||
If you don't like docker compose, don't want a bare-metal installation, but still want to leverage the benefits from the isolation and modularity of containers - this is the guide you should use. | ||
|
||
> Likewise, If you are actively developing LibreChat, aren't using the service productively (i.e production environments), you should avoid this guide and look to something easier to work with such as docker compose. | ||
**Important:** `docker` and `podman` commands are for the most part, interoperable and interchangeable. Since podman should be the better "Libre" choice, code instructions below will use (and heavily favor) `podman` - and some commands will need to be tweaked to compensate for this. | ||
|
||
|
||
## Creating the base image | ||
|
||
Since LibreChat is very active in development, it's recommended for now to build | ||
the image locally for the container you plan on using. Thankfully this is easy enough to do. | ||
|
||
In your target directory, run the following: | ||
```bash | ||
git clone https://github.com/danny-avila/LibreChat | ||
``` | ||
|
||
This will add a directory, `LibreChat` into your local environment. | ||
|
||
Without entering the `LibreChat` directory, add a script `./image.sh` with the following: | ||
|
||
> If you don't want to run this as a script, you can run the container command rather images | ||
```bash | ||
# Build the base container image (which contains the LibreChat stack - api, client and data providers) | ||
podman build \ | ||
--tag "librechat:local" \ | ||
--file ./LibreChat/Dockerfile; | ||
``` | ||
|
||
> Not the downside of running a base container that has a live root is that image revisions need to be done manually. The easiest way is to remove and recreate the image when the container is no longer. If that's not possible for you, manually updating the image to increment versions can be done manually. Simply amend $image with the version you're building. | ||
> We'll document how to go about the update process more effectively further on. You wont need to remove your existing containers, or lose any data when updating. | ||
## Setting up the env file | ||
|
||
Execute the following command to create a env file solely for LibreChat containers: | ||
|
||
```bash | ||
cp ./LibreChat/.env.example .env | ||
``` | ||
|
||
This will add the env file to the top level directory that we will create the containers, allowing us to pass it easily as via the `--env-file` command argument. | ||
|
||
Follow [this guide](https://docs.librechat.ai/install/free_ai_apis.html) to populate the containers with the correct env values for various apis. There are other env values of interest that might be worth changing, documented within the env itself. Afterwords, edit the following lines in the `.env` file. | ||
|
||
``` | ||
HOST=0.0.0.0 | ||
MONGO_URI=mongodb://librechat-mongodb:27017/LibreChat | ||
MEILI_HOST=http://librechat-meilisearch:7700 | ||
MEILI_HTTP_ADDR=librechat-meilisearch:7700 | ||
MEILI_NO_ANALYTICS=true | ||
``` | ||
|
||
These values will be uses by some of our containers to correctly use container DNS, using the LibreChat network. | ||
|
||
## Creating a network for LibreChat | ||
|
||
If you're going about this the _manual_ way, it's likely safe to assume you're running more than a few different containers and services on your machine. One of the nice features offered by most container engines is that you don't need to have every single container exposed on the host network. This has the added benefit of not exposing your data and dependant services to other containers on your host. | ||
|
||
```bash | ||
podman network create librechat | ||
``` | ||
|
||
We will be using this network when creating our containers. | ||
|
||
## Creating dependant containers | ||
|
||
LibreChat currently uses mongoDB and meilisearch, so we'll also be creating those containers. | ||
|
||
## Mongodb | ||
|
||
Install and boot the mongodb container with the following command: | ||
|
||
```bash | ||
podman run \ | ||
--name="librechat-mongodb" \ | ||
--network=librechat \ | ||
-v "librechat-mongodb-data:/data/db" \ | ||
--detach \ | ||
docker.io/mongo \ | ||
mongod --noauth; | ||
``` | ||
|
||
## Meilisearch | ||
|
||
Install and boot the melisearch container with the following command: | ||
|
||
```bash | ||
podman run \ | ||
--name="librechat-meilisearch" \ | ||
--network=librechat \ | ||
--env-file="./.env" \ | ||
-v "librechat-meilisearch-data:/meili_data" \ | ||
--detach \ | ||
docker.io/getmeili/meilisearch:v1.0; | ||
``` | ||
|
||
## Starting LibreChat | ||
```bash | ||
podman run \ | ||
--name="librechat" \ | ||
--network=librechat \ | ||
--env-file="./.env" \ | ||
-p 3080:3080 \ | ||
--detach \ | ||
librechat:local; | ||
``` | ||
|
||
If you're using LibreChat behind another load balancer, you can omit the `-p` declaration, you can also attach the container to the same network by adding an additional network argument: | ||
|
||
```bash | ||
--network=librechat \ | ||
--network=mybalancernetwork \ | ||
``` | ||
|
||
As described by the original `-p` command argument, it would be possible to access librechat as `librechat:3080`, `mybalancernetwork` would be replaced with whatever network your balancer exists. | ||
|
||
## Auto-starting containers on boot (podman + Linux only) | ||
|
||
Podman has a declarative way to ensure that pod starts up automatically on system boot using systemd. | ||
|
||
To use this method you need to run the following commands: | ||
|
||
First, let's stop any running containers related to LibreChat: | ||
s | ||
```bash | ||
podman stop librechat librechat-mongodb librechat-meilisearch | ||
``` | ||
|
||
Next, we'll update our user's systemd configuration to enable lingering. In systemd-based systems, when a user logs in and out, user-based services typically terminate themselves to save CPU, but since we're using rootless containers (which is podman's preferred way of running), we need to indicate that our user has permission to have user-locked services running after their session ends. | ||
|
||
```bash | ||
loginctl enable-linger $(whoami) | ||
``` | ||
|
||
Next, we'll create a script somewhere in our `home` directory using a text editor. Let's call the script `./install.sh` | ||
|
||
```bash | ||
#!/bin/bash | ||
# Install podman container as systemd container | ||
set -e | ||
name="$1"; | ||
podman generate systemd --name "$name" > ~/.config/systemd/user/container-$name.service | ||
systemctl --user enable --now container-$name; | ||
``` | ||
|
||
After saving, we'll update the script to be executable: | ||
|
||
```bash | ||
chmod +x ./install.sh | ||
``` | ||
|
||
Assuming we aren't running those LibreChat containers from before, we can enable on-boot services for each of them using the following: | ||
|
||
```bash | ||
./install.sh librechat-mongodb | ||
./install.sh librechat-meilisearch | ||
./install.sh librechat | ||
``` | ||
|
||
The containers (assuming everything was done to par), will be now running using the systemd layer instead of the podman layer. This means services will load on boot, but also means managing these containers is a little more manual and requires interacting with systemd instead of podman directly. | ||
|
||
For instance, instead of `podman stop {name}`, you would instead do `systemctl --user stop container-{name}` to perform maintenance (such as updates or backups). Likewise, if you need to start the service again you simply can run `systemctl --user start container-{name}`. If wanting to use auto-boot functionality, interacting with managed containers using podman can cause issues with systemd's fault tolerance as it can't correctly indicate the state of a container when interfered with. | ||
|
||
## Backing up volume containers (podman only) | ||
|
||
The podman containers above are using named volumes for persistent data, which means we can't simply copy files from one place to another. This has benefits though. In podman, we can simply backup the volume into a tape archive format (tarball). To do this, run the following commands: | ||
|
||
> It's recommended you stop the containers before running these commands. | ||
```bash | ||
# backup the | ||
podman volume export librechat-meilisearch-data --output "librechat-meilisearch-backup-$(date +"%d-%m-%Y").tar" | ||
podman volume export librechat-mongodb-data --output "librechat-mongodb-backup-$(date +"%d-%m-%Y").tar" | ||
``` | ||
|
||
These will leave archive files that you can do what you wish with, including reverting volumes to a previous state if needed. Refer to [podman documentation](https://docs.podman.io/en/latest/markdown/podman-volume-import.1.html) for how to do this. | ||
|
||
## Updating LibreChat | ||
|
||
LibreChat is still under development, so depending on published images isn't a huge viability at the moment. Instead, it's easier to update using git. Data persistence in librechat is managed outside of the main container, so it's rather simple to do an in-place update. | ||
|
||
In the parent directory containing the LibreChat repo: | ||
|
||
```bash | ||
# Update the git repo | ||
(cd LibreChat && git pull); | ||
|
||
# (ONLY if using systemd auto start) Stop the service | ||
systemctl --user stop container-librechat | ||
|
||
# Remove the librechat container | ||
podman rm -f librechat | ||
|
||
# Destroy the local image | ||
podman rmi -f librechat:local | ||
|
||
# Rebuild the image | ||
podman build \ | ||
--tag "librechat:local" \ | ||
--file ./LibreChat/Dockerfile; | ||
|
||
# Recreate the container (using the Starting LibreChat step) | ||
podman run \ | ||
--name="librechat" \ | ||
--network=librechat \ | ||
--env-file="./.env" \ | ||
-p 3080:3080 \ | ||
--detach \ | ||
librechat:local; | ||
|
||
# Stop the container (if it's confirmed to be running) and restart the service | ||
podman stop librechat && systemctl --user start container-librechat | ||
``` |
4 changes: 2 additions & 2 deletions
4
docs/install/docker_install.md → docs/install/docker_compose_install.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters