Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐳 : Improving Docker Build #1415

Merged
merged 6 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
**/node_modules
client/dist/images
node_modules
data-node
.env
**/.env
librechat.yaml
meili_data*
librechat*
Dockerfile*
# Ignore all hidden files
.*
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Base node image
FROM node:19-alpine AS node
FROM node:18-alpine AS node

COPY . /app
WORKDIR /app

# Allow mounting of these files, which have no default
# values.
RUN touch .env librechat.yaml
# Install call deps - Install curl for health check
RUN apk --no-cache add curl && \
# We want to inherit env from the container, not the file
# This will preserve any existing env file if it's already in source
# otherwise it will create a new one
touch .env && \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact I only realized now why this might in fact be useful:

when running docker-compose up without a .env file, docker-compose creates a directory called .env. This might confuse users (at least it would confuse me) when they want to add the .env file later.

So it might be useful to keep this touch .env here, but adjust the comment accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact that doesn't work. I just tried it, and if the .env file doesn't exist in the user directory, docker will create a directory anyway, even if the docker-image has a .env file!

# Build deps in seperate
npm ci
npm ci

# React client build
ENV NODE_OPTIONS="--max-old-space-size=2048"
Expand Down
11 changes: 1 addition & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@ services:
restart: always
user: "${UID}:${GID}"
extra_hosts:
- "host.docker.internal:host-gateway"
env_file:
- .env
- "host.docker.internal:host-gateway"
environment:
- HOST=0.0.0.0
- MONGO_URI=mongodb://mongodb:27017/LibreChat
- MEILI_HOST=http://meilisearch:7700
volumes:
- /app/client/node_modules
- /app/api/node_modules
- ./api:/app/api
- ./.env:/app/.env
- ./.env.development:/app/.env.development
- ./.env.production:/app/.env.production
- ./images:/app/client/public/images
- ./librechat.yaml:/app/librechat.yaml
mongodb:
Expand All @@ -45,8 +38,6 @@ services:
container_name: chat-meilisearch
image: getmeili/meilisearch:v1.5
restart: always
env_file:
- .env
user: "${UID}:${GID}"
environment:
- MEILI_HOST=http://meilisearch:7700
Expand Down
30 changes: 15 additions & 15 deletions docs/install/installation/docker_compose_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ Install Docker on your system. **[Docker Desktop](https://www.docker.com/product
### LibreChat Configuration
Before running LibreChat with Docker, you need to configure some settings:

- Edit the credentials you see in `docker-compose.yml` under the API service as needed.
- See my notes below for specific instructions on some of the configuration
- Provide all necessary credentials in the `.env` file before the next step.
- Docker will read this env file. See the **[/.env.example](https://github.com/danny-avila/LibreChat/blob/main/.env.example)** file for reference.
- If you want to change the `docker-compose.yml` file, please create a `docker-compose.override.yml` file based on the `docker-compose.override.yml.example`.
This allows you to update without having to modify `docker-compose.yml`.
- Either create an empty `librechat.yaml` file or use the example from `librechat.example.yaml`.

#### [AI Setup](../configuration/ai_setup.md) (Required)
At least one AI endpoint should be setup for use.
Expand All @@ -42,17 +43,18 @@ How to set up the user/auth system and Google login.
### Running LibreChat
Once you have completed all the setup, you can start the LibreChat application by running the command `docker-compose up` in your terminal. After running this command, you can access the LibreChat application at `http://localhost:3080`.

If you build your own containers out of the git checkout with `docker-compose up --build` you should pre-create the mount points for the volumes. This avoids occasional trouble with directory permissions when rebuilding:
```
mkdir meili_data images .env.production .env.development data-node
```

**Note:** MongoDB does not support older ARM CPUs like those found in Raspberry Pis. However, you can make it work by setting MongoDB’s version to mongo:4.4.18 in docker-compose.yml, the most recent version compatible with

That's it! If you need more detailed information on configuring your compose file, see my notes below.

## Updating LibreChat
- Run `npm run update` from the project directory for a clean installation.
The following commands will fetch the latest code of LibreChat and build a new docker image.

```bash
git pull
docker-compose down
docker-compose up --build
```

If you're having issues running this command, you can try running what the script does manually:

Expand All @@ -61,15 +63,15 @@ Prefix commands with `sudo` according to your environment permissions.
```bash
# Stop the container (if running)
docker-compose down
# Fetch the latest changes from Github
git fetch origin
# Switch to the repo's main branch
git checkout main
# Pull the latest changes to the main branch from Github
git pull origin main
git pull
ineiti marked this conversation as resolved.
Show resolved Hide resolved
# Prune all LibreChat Docker images
docker rmi librechat:latest
# Remove all unused dangling Docker images
# Remove all unused dangling Docker images.
# Be careful, as this will delete all dangling docker images on your
# computer, also those not created by LibreChat!
docker image prune -f
# Building a new LibreChat image without cache
docker-compose build --no-cache
Expand All @@ -83,6 +85,7 @@ docker-compose up
### Config notes for docker-compose.yml file

Modification to the `docker-compose.yml` should be made with `docker-compose.override.yml` whenever possible to prevent conflicts when updating. You can create a new file named `docker-compose.override.yml` in the same directory as your main `docker-compose.yml` file for LibreChat, where you can set your .env variables as needed under `environment`, or modify the default configuration provided by the main `docker-compose.yml`, without the need to directly edit or duplicate the whole file.
The file `docker-compose.override.yml.example` gives some examples of the most common reconfiguration options used.

For more info see:

Expand All @@ -94,9 +97,6 @@ For more info see:
- **[docker docs - merge-compose-files](https://docs.docker.com/compose/multiple-compose-files/merge/#merge-compose-files)**
- **[docker docs - specifying-multiple-compose-files](https://docs.docker.com/compose/reference/#specifying-multiple-compose-files)**

- You can also view an example of an override file for LibreChat in your LibreChat folder and on GitHub:
- **[docker-compose.override.example](https://github.com/danny-avila/LibreChat/blob/main/docker-compose.override.yaml.example)**

- Any environment variables set in your compose file will override variables with the same name in your .env file. Note that the following variables are necessary to include in the compose file so they work in the docker environment, so they are included for you.

```yaml
Expand Down