2024-04-10 16:28:48 +00:00
---
2026-01-27 14:14:58 +00:00
title: Deploying LobeHub Database with Docker
2024-04-10 16:28:48 +00:00
description: >-
2026-01-27 14:14:58 +00:00
Learn how to deploy the LobeHub server database version using Docker on Linux
and local machines.
2024-04-10 16:28:48 +00:00
tags:
2026-01-27 14:14:58 +00:00
- LobeHub
- Docker
- Database Deployment
- Postgres
2024-04-10 16:28:48 +00:00
---
2024-04-11 03:08:25 +00:00
2026-01-27 14:14:58 +00:00
# Deploying Server Database Version Using Docker
2024-02-18 13:39:04 +00:00
2024-03-17 14:23:30 +00:00
<div style={{display:"flex", gap: 4}}>
[![][docker-release-shield]][docker-release-link]
2025-01-08 13:32:57 +00:00
[![][docker-size-shield]][docker-size-link]
2024-03-17 14:23:30 +00:00
2025-01-08 13:32:57 +00:00
[![][docker-pulls-shield]][docker-pulls-link]
2024-03-17 14:23:30 +00:00
</div>
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
<Callout type="info">
This article assumes that you are familiar with the basic principles and processes of deploying
the LobeHub server database version, so it only includes content related to core environment
variable configuration. If you are not familiar with the deployment principles of the LobeHub
server database version, please refer to [Deploying Server
Database](/docs/self-hosting/server-database) first.
</Callout>
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
## Deploying on a Linux Server
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
Here is the process for deploying the LobeHub server database version on a Linux server:
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
<Steps>
### Create a Postgres Database Instance
2024-04-11 03:08:25 +00:00
2026-01-30 12:50:05 +00:00
Please create a Postgres database instance according to your needs, for example:
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
```sh
docker network create pg
2024-02-18 13:39:04 +00:00
2026-01-30 12:50:05 +00:00
docker run --name my-postgres --network pg -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d paradedb/paradedb:latest-pg17
2025-01-08 13:32:57 +00:00
```
2024-02-18 13:39:04 +00:00
2026-01-30 12:50:05 +00:00
The above command will create a PG instance named `my-postgres` on the network `pg`, where `paradedb/paradedb:latest-pg17` is a Postgres 17 image with pgvector and pg\_search plugins installed by default.
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
<Callout type="info">
2026-01-30 12:50:05 +00:00
The ParadeDB image includes pgvector (vector search) and pg\_search (full-text search) plugins, which are important
components for LobeHub to implement RAG and knowledge base search.
2025-01-08 13:32:57 +00:00
</Callout>
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
<Callout type="warning">
The above command does not specify a persistent storage location for the pg instance, so it is
only for testing/demonstration purposes. Please configure persistent storage for production
environments.
2025-01-08 13:32:57 +00:00
</Callout>
2024-04-11 03:08:25 +00:00
2026-03-14 14:06:09 +00:00
### Create a file named `lobehub.env` to store environment variables:
2024-02-18 13:39:04 +00:00
2026-01-27 17:14:53 +00:00
Click the buttons below to generate required secrets:
<GenerateSecret envName="KEY_VAULTS_SECRET" />
<GenerateSecret envName="AUTH_SECRET" />
2026-01-31 11:46:44 +00:00
Click the button below to generate `JWKS_KEY` (for signing and verifying JWTs):
<GenerateJWKSKey />
2026-01-27 14:14:58 +00:00
```shell
# Website domain
APP_URL=https://your-prod-domain.com
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
# DB required environment variables
KEY_VAULTS_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk=
# Postgres database connection string
# Format: postgres://username:password@host:port/dbname; if your pg instance is a Docker container, use the container name
DATABASE_URL=postgres://postgres:mysecretpassword@my-postgres:5432/postgres
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
# Authentication (Better Auth)
# Session encryption key (generate with: openssl rand -base64 32)
AUTH_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk=
2026-01-31 11:46:44 +00:00
# JWKS key for signing and verifying JWTs
2026-01-27 14:14:58 +00:00
JWKS_KEY='{"keys":[...]}'
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
# S3 related
S3_ACCESS_KEY_ID=xxxxxxxxxx
S3_SECRET_ACCESS_KEY=xxxxxxxxxx
S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com
S3_BUCKET=LobeHub
2024-02-18 13:39:04 +00:00
2025-01-08 13:32:57 +00:00
```
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
### Start the lobehub Docker image
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
```sh
2026-03-14 14:06:09 +00:00
docker run -it -d -p 3210:3210 --network pg --env-file lobehub.env --name lobehub lobehub/lobehub
2026-01-27 14:14:58 +00:00
```
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
You can use the following command to check the logs:
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
```sh
docker logs -f lobehub
2025-01-08 13:32:57 +00:00
```
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
If you see the following logs in the container, it means it has started successfully:
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
```log
[Database] Start to migration...
✅ database migration pass.
-------------------------------------
▲ Next.js 14.x.x
- Local: http://localhost:3210
- Network: http://0.0.0.0:3210
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
✓ Starting...
✓ Ready in 95ms
2025-01-08 13:32:57 +00:00
```
2024-03-10 10:46:41 +00:00
</Steps>
2024-02-18 13:39:04 +00:00
2026-01-27 14:14:58 +00:00
<Callout type="tip">
In our official Docker image, the database schema migration is automatically executed before
starting the image. We ensure stability from an empty database to all tables being formally
available. Therefore, we recommend using an empty table instance for your database to avoid the
cost of manually maintaining table structure migration.
</Callout>
## Using Locally (Mac / Windows)
The data version of LobeHub also supports direct use on a local Mac/Windows machine.
Here, we assume that you have a pg instance available on port 5432 locally on your Mac/Windows, with the account `postgres` and password `mysecretpassword`, accessible at `localhost:5432`.
The script command you need to execute is:
```shell
$ docker run -it -d --name lobehub -p 3210:3210 \
-e DATABASE_URL=postgres://postgres:mysecretpassword@host.docker.internal:5432/postgres \
-e KEY_VAULTS_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk= \
-e AUTH_SECRET=jgwsK28dspyVQoIf8/M3IIHl1h6LYYceSYNXeLpy6uk= \
-e JWKS_KEY='{"keys":[...]}' \
-e APP_URL=http://localhost:3210 \
-e S3_ACCESS_KEY_ID=xxxxxxxxxx \
-e S3_SECRET_ACCESS_KEY=xxxxxxxxxx \
-e S3_ENDPOINT=https://xxxxxxxxxx.r2.cloudflarestorage.com \
-e S3_BUCKET=LobeHub \
lobehub/lobehub
```
<Callout type="tip">
`Docker` uses a virtual machine solution on `Windows` and `macOS`. If you use `localhost` /
`127.0.0.1`, it will refer to the container's `localhost`. In this case, try using
`host.docker.internal` instead of `localhost`.
</Callout>
[docker-pulls-link]: https://hub.docker.com/r/lobehub/lobehub
[docker-pulls-shield]: https://img.shields.io/docker/pulls/lobehub/lobehub?color=45cc11&labelColor=black&style=flat-square
[docker-release-link]: https://hub.docker.com/r/lobehub/lobehub
[docker-release-shield]: https://img.shields.io/docker/v/lobehub/lobehub?color=369eff&label=docker&labelColor=black&logo=docker&logoColor=white&style=flat-square&sort=semver
[docker-size-link]: https://hub.docker.com/r/lobehub/lobehub
[docker-size-shield]: https://img.shields.io/docker/image-size/lobehub/lobehub?color=369eff&labelColor=black&style=flat-square&sort=semver