mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
docs(docker): document shared data setup
This commit is contained in:
1 parent
179b8c12c2
commit
a66d77f80f
3 files changed
+298
-32
No files matched your search
+95
-10
@@ -12,6 +12,50 @@ ghcr.io/chatlab/chatlab-cli
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 与 Desktop / 本地 CLI 共用数据(推荐)
|
||||
|
||||
ChatLab 的 Desktop、CLI 和 Docker 都可以使用宿主机的 `~/.chatlab`。本机运行 Docker 时,建议直接挂载这个目录:
|
||||
|
||||
macOS / Linux:
|
||||
|
||||
```bash
|
||||
mkdir -p "$HOME/.chatlab" "$HOME/Downloads"
|
||||
|
||||
docker run --name chatlab \
|
||||
-p 127.0.0.1:3110:3110 \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
Windows PowerShell:
|
||||
|
||||
```powershell
|
||||
New-Item -ItemType Directory -Force "$HOME/.chatlab" | Out-Null
|
||||
|
||||
docker run --name chatlab `
|
||||
-p 127.0.0.1:3110:3110 `
|
||||
--mount "type=bind,source=$HOME/.chatlab,target=/home/node/.chatlab" `
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data `
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
容器启动后,打开 <http://127.0.0.1:3110/>。
|
||||
|
||||
镜像默认使用非特权 `node` 用户(UID/GID 1000)运行。在 macOS 和 Linux 上,`--user` 会让容器进程使用宿主机当前用户的 UID/GID,`HOME` 则确保 ChatLab 的系统目录仍是 `/home/node/.chatlab`。对于当前用户 UID/GID 不是 1000 的 Linux 主机,这两个参数是必需的。宿主机的 `~/.chatlab` 对应容器内的 `/home/node/.chatlab`,`~/Downloads` 对应容器内可写的下载目录;`CHATLAB_DATA_DIR` 将默认用户数据固定到容器可访问的 `/home/node/.chatlab/data`,避免宿主机 `config.toml` 中的绝对路径在容器内失效。
|
||||
|
||||
使用这组命令后,两种切换都不需要复制数据:
|
||||
|
||||
- 先使用 Docker,之后安装 Desktop 或本地 CLI:Desktop / CLI 会继续读取宿主机 `~/.chatlab`。
|
||||
- 已经使用 Desktop 或本地 CLI,之后启动 Docker:Docker 会直接读取原有的配置、聊天数据库和 AI 数据。
|
||||
|
||||
### 使用独立 Docker 数据
|
||||
|
||||
在服务器上部署,或者明确不想与宿主机上的 ChatLab 共用数据时,可以使用 Docker named volume:
|
||||
|
||||
```bash
|
||||
docker run --name chatlab \
|
||||
-p 127.0.0.1:3110:3110 \
|
||||
@@ -19,9 +63,27 @@ docker run --name chatlab \
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
容器启动后,打开 <http://127.0.0.1:3110/>。
|
||||
该数据卷会保留容器内的系统状态和用户数据,但 Desktop 和宿主机 CLI **不会**自动看到其中的数据。替换或升级容器时,请保留 `chatlab-data` 数据卷。
|
||||
|
||||
镜像使用非特权 `node` 用户运行。该数据卷会保留 `/home/node/.chatlab` 下的系统状态和用户数据。替换或升级容器时,请保留该数据卷。
|
||||
### 自定义用户数据目录
|
||||
|
||||
如果 Desktop / CLI 已将聊天数据库移动到 `~/.chatlab` 之外,还需要挂载该目录,并让环境变量指向对应的容器路径:
|
||||
|
||||
```bash
|
||||
docker run --name chatlab \
|
||||
-p 127.0.0.1:3110:3110 \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
--mount type=bind,source="/absolute/path/to/chatlab-data",target=/chatlab-data \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/chatlab-data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
请将 `/absolute/path/to/chatlab-data` 替换为宿主机上的真实用户数据目录。系统数据仍通过 `~/.chatlab` 挂载。由于 `CHATLAB_DATA_DIR` 的优先级最高,Docker 的数据目录应通过挂载和环境变量调整,而不是在存储管理页面中切换。
|
||||
|
||||
同一版本的 Desktop、CLI 和 Docker 可以共享数据库。切换数据目录、执行迁移或跨版本使用前,建议先停止其他 ChatLab 实例;如果旧版本无法安全读取已经升级的数据目录,ChatLab 会通过兼容门禁拒绝启动。
|
||||
|
||||
## 服务选项
|
||||
|
||||
@@ -48,7 +110,11 @@ Docker 参数会替换完整的默认命令。添加服务选项时,需要按
|
||||
```bash
|
||||
docker run --rm \
|
||||
-p 127.0.0.1:8080:8080 \
|
||||
-v chatlab-data:/home/node/.chatlab \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest \
|
||||
start --port 8080 --host 0.0.0.0 --headless --no-open
|
||||
```
|
||||
@@ -58,8 +124,13 @@ docker run --rm \
|
||||
```bash
|
||||
docker run --rm ghcr.io/chatlab/chatlab-cli:latest --version
|
||||
docker run --rm ghcr.io/chatlab/chatlab-cli:latest formats
|
||||
docker run --rm -v chatlab-data:/home/node/.chatlab \
|
||||
ghcr.io/chatlab/chatlab-cli:latest sessions --format json
|
||||
docker run --rm \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest sessions list --format json
|
||||
```
|
||||
|
||||
## 环境变量
|
||||
@@ -98,15 +169,32 @@ Bearer Token、无界面模式、Web UI 认证和浏览器打开行为通过对
|
||||
|
||||
## Docker Compose
|
||||
|
||||
先在 Compose 文件旁创建未跟踪的 `.env`:
|
||||
|
||||
```dotenv
|
||||
CHATLAB_HOST_DIR=/absolute/path/to/.chatlab
|
||||
CHATLAB_DOWNLOADS_DIR=/absolute/path/to/Downloads
|
||||
CHATLAB_UID=1000
|
||||
CHATLAB_GID=1000
|
||||
CHATLAB_TOKEN=replace-with-a-secret-token
|
||||
```
|
||||
|
||||
将 `CHATLAB_HOST_DIR` 替换为宿主机的 `~/.chatlab` 绝对路径,并将 `CHATLAB_DOWNLOADS_DIR` 设置为一个已存在且可写的导出和截图目录,例如宿主机的 `~/Downloads`。在 macOS 和 Linux 上,还需要将 `CHATLAB_UID`、`CHATLAB_GID` 分别替换为 `id -u`、`id -g` 的输出;Windows Docker Desktop 可以保留 `1000`。
|
||||
|
||||
```yaml
|
||||
services:
|
||||
chatlab:
|
||||
image: ghcr.io/chatlab/chatlab-cli:latest
|
||||
restart: unless-stopped
|
||||
user: "${CHATLAB_UID:-1000}:${CHATLAB_GID:-1000}"
|
||||
ports:
|
||||
- "127.0.0.1:3110:3110"
|
||||
environment:
|
||||
HOME: /home/node
|
||||
CHATLAB_DATA_DIR: /home/node/.chatlab/data
|
||||
volumes:
|
||||
- chatlab-data:/home/node/.chatlab
|
||||
- "${CHATLAB_HOST_DIR:?set CHATLAB_HOST_DIR in the Compose environment}:/home/node/.chatlab"
|
||||
- "${CHATLAB_DOWNLOADS_DIR:?set CHATLAB_DOWNLOADS_DIR in the Compose environment}:/home/node/Downloads"
|
||||
command:
|
||||
- start
|
||||
- --port
|
||||
@@ -117,12 +205,9 @@ services:
|
||||
- ${CHATLAB_TOKEN:?set CHATLAB_TOKEN in the Compose environment}
|
||||
- --require-auth
|
||||
- --no-open
|
||||
|
||||
volumes:
|
||||
chatlab-data:
|
||||
```
|
||||
|
||||
`CHATLAB_TOKEN` 由 Docker Compose 插值后作为 `--token` 的值传给 ChatLab,并不是 ChatLab 环境变量。请将其保存在密钥存储或未跟踪的 `.env` 文件中。
|
||||
`CHATLAB_TOKEN` 由 Docker Compose 插值后作为 `--token` 的值传给 ChatLab,并不是 ChatLab 环境变量。请将其保存在密钥存储或未跟踪的 `.env` 文件中。如果需要完全独立的服务器数据,请改用上文“使用独立 Docker 数据”中的 named volume。
|
||||
|
||||
## 多架构镜像
|
||||
|
||||
|
||||
+108
-12
@@ -13,6 +13,58 @@ ghcr.io/chatlab/chatlab-cli
|
||||
|
||||
## Quick start
|
||||
|
||||
### Share data with Desktop and a local CLI (recommended)
|
||||
|
||||
ChatLab Desktop, CLI, and Docker can all use the host's `~/.chatlab` directory. When running Docker locally, bind mount that directory directly:
|
||||
|
||||
macOS / Linux:
|
||||
|
||||
```bash
|
||||
mkdir -p "$HOME/.chatlab" "$HOME/Downloads"
|
||||
|
||||
docker run --name chatlab \
|
||||
-p 127.0.0.1:3110:3110 \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
Windows PowerShell:
|
||||
|
||||
```powershell
|
||||
New-Item -ItemType Directory -Force "$HOME/.chatlab" | Out-Null
|
||||
|
||||
docker run --name chatlab `
|
||||
-p 127.0.0.1:3110:3110 `
|
||||
--mount "type=bind,source=$HOME/.chatlab,target=/home/node/.chatlab" `
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data `
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
Open <http://127.0.0.1:3110/> after the container starts.
|
||||
|
||||
The image normally runs as the unprivileged `node` user (UID/GID 1000). On
|
||||
macOS and Linux, `--user` matches the container process to the owner of the bind
|
||||
mount, while `HOME` keeps ChatLab's system directory at `/home/node/.chatlab`.
|
||||
This is required on Linux hosts whose user UID/GID is not 1000. The host's
|
||||
`~/.chatlab` maps to `/home/node/.chatlab`, and the host's `~/Downloads` maps
|
||||
to the container's writable Downloads directory.
|
||||
`CHATLAB_DATA_DIR` pins the default user data to the container-accessible
|
||||
`/home/node/.chatlab/data`, so absolute paths from the host's `config.toml` do
|
||||
not break inside the container.
|
||||
|
||||
With this setup, neither direction requires copying data:
|
||||
|
||||
- Start with Docker, then install Desktop or the local CLI: Desktop and CLI continue to read the host's `~/.chatlab`.
|
||||
- Start with Desktop or the local CLI, then run Docker: Docker reads the existing configuration, chat databases, and AI data.
|
||||
|
||||
### Use Docker-only data
|
||||
|
||||
For a server deployment, or when you explicitly want data isolated from ChatLab on the host, use a Docker named volume:
|
||||
|
||||
```bash
|
||||
docker run --name chatlab \
|
||||
-p 127.0.0.1:3110:3110 \
|
||||
@@ -20,11 +72,27 @@ docker run --name chatlab \
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
Open <http://127.0.0.1:3110/> after the container starts.
|
||||
This volume preserves system state and user data inside Docker, but Desktop and the host CLI do **not** see that data automatically. Keep the `chatlab-data` volume when replacing or upgrading the container.
|
||||
|
||||
The image runs as the unprivileged `node` user. The volume preserves system
|
||||
state and user data under `/home/node/.chatlab`. Keep it when replacing or
|
||||
upgrading the container.
|
||||
### Use a custom user data directory
|
||||
|
||||
If Desktop or CLI stores chat databases outside `~/.chatlab`, mount that directory separately and point the environment variable at its container path:
|
||||
|
||||
```bash
|
||||
docker run --name chatlab \
|
||||
-p 127.0.0.1:3110:3110 \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
--mount type=bind,source="/absolute/path/to/chatlab-data",target=/chatlab-data \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/chatlab-data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
Replace `/absolute/path/to/chatlab-data` with the actual user data directory on the host. System data remains shared through the `~/.chatlab` mount. Because `CHATLAB_DATA_DIR` has the highest priority, change Docker's data directory through its mount and environment variable rather than the Storage settings page.
|
||||
|
||||
Desktop, CLI, and Docker on the same version can share the database. Before changing the data directory, running a migration, or switching between different versions, stop the other ChatLab instances first. If an older version cannot safely read an upgraded data directory, ChatLab's compatibility gate blocks startup.
|
||||
|
||||
## Server options
|
||||
|
||||
@@ -52,7 +120,11 @@ Docker arguments replace the complete default command. Repeat `start`,
|
||||
```bash
|
||||
docker run --rm \
|
||||
-p 127.0.0.1:8080:8080 \
|
||||
-v chatlab-data:/home/node/.chatlab \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest \
|
||||
start --port 8080 --host 0.0.0.0 --headless --no-open
|
||||
```
|
||||
@@ -62,8 +134,13 @@ Other CLI commands can be selected directly:
|
||||
```bash
|
||||
docker run --rm ghcr.io/chatlab/chatlab-cli:latest --version
|
||||
docker run --rm ghcr.io/chatlab/chatlab-cli:latest formats
|
||||
docker run --rm -v chatlab-data:/home/node/.chatlab \
|
||||
ghcr.io/chatlab/chatlab-cli:latest sessions --format json
|
||||
docker run --rm \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest sessions list --format json
|
||||
```
|
||||
|
||||
## Environment variables
|
||||
@@ -105,15 +182,36 @@ provide environment-variable aliases for those options.
|
||||
|
||||
## Docker Compose
|
||||
|
||||
First, create an untracked `.env` next to the Compose file:
|
||||
|
||||
```dotenv
|
||||
CHATLAB_HOST_DIR=/absolute/path/to/.chatlab
|
||||
CHATLAB_DOWNLOADS_DIR=/absolute/path/to/Downloads
|
||||
CHATLAB_UID=1000
|
||||
CHATLAB_GID=1000
|
||||
CHATLAB_TOKEN=replace-with-a-secret-token
|
||||
```
|
||||
|
||||
Replace `CHATLAB_HOST_DIR` with the absolute path to the host's `~/.chatlab`.
|
||||
Set `CHATLAB_DOWNLOADS_DIR` to an existing writable directory for exports and
|
||||
screenshots, such as the host's `~/Downloads`.
|
||||
On macOS and Linux, replace `CHATLAB_UID` and `CHATLAB_GID` with the output of
|
||||
`id -u` and `id -g`. Windows Docker Desktop users can keep `1000`.
|
||||
|
||||
```yaml
|
||||
services:
|
||||
chatlab:
|
||||
image: ghcr.io/chatlab/chatlab-cli:latest
|
||||
restart: unless-stopped
|
||||
user: "${CHATLAB_UID:-1000}:${CHATLAB_GID:-1000}"
|
||||
ports:
|
||||
- "127.0.0.1:3110:3110"
|
||||
environment:
|
||||
HOME: /home/node
|
||||
CHATLAB_DATA_DIR: /home/node/.chatlab/data
|
||||
volumes:
|
||||
- chatlab-data:/home/node/.chatlab
|
||||
- "${CHATLAB_HOST_DIR:?set CHATLAB_HOST_DIR in the Compose environment}:/home/node/.chatlab"
|
||||
- "${CHATLAB_DOWNLOADS_DIR:?set CHATLAB_DOWNLOADS_DIR in the Compose environment}:/home/node/Downloads"
|
||||
command:
|
||||
- start
|
||||
- --port
|
||||
@@ -124,14 +222,12 @@ services:
|
||||
- ${CHATLAB_TOKEN:?set CHATLAB_TOKEN in the Compose environment}
|
||||
- --require-auth
|
||||
- --no-open
|
||||
|
||||
volumes:
|
||||
chatlab-data:
|
||||
```
|
||||
|
||||
`CHATLAB_TOKEN` is interpolated by Docker Compose and passed to ChatLab as the
|
||||
value of `--token`; it is not a ChatLab environment variable. Keep it in a
|
||||
secret store or an untracked `.env` file.
|
||||
secret store or an untracked `.env` file. If you need completely isolated
|
||||
server data, use the named volume from "Use Docker-only data" above instead.
|
||||
|
||||
## Multi-architecture images
|
||||
|
||||
|
||||
+95
-10
@@ -12,6 +12,50 @@ ghcr.io/chatlab/chatlab-cli
|
||||
|
||||
## 快速開始
|
||||
|
||||
### 與 Desktop / 本機 CLI 共用資料(建議)
|
||||
|
||||
ChatLab Desktop、CLI 和 Docker 都可以使用主機的 `~/.chatlab`。在本機執行 Docker 時,建議直接掛載此目錄:
|
||||
|
||||
macOS / Linux:
|
||||
|
||||
```bash
|
||||
mkdir -p "$HOME/.chatlab" "$HOME/Downloads"
|
||||
|
||||
docker run --name chatlab \
|
||||
-p 127.0.0.1:3110:3110 \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
Windows PowerShell:
|
||||
|
||||
```powershell
|
||||
New-Item -ItemType Directory -Force "$HOME/.chatlab" | Out-Null
|
||||
|
||||
docker run --name chatlab `
|
||||
-p 127.0.0.1:3110:3110 `
|
||||
--mount "type=bind,source=$HOME/.chatlab,target=/home/node/.chatlab" `
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data `
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
容器啟動後,開啟 <http://127.0.0.1:3110/>。
|
||||
|
||||
映像預設使用非特權 `node` 使用者(UID/GID 1000)執行。在 macOS 和 Linux 上,`--user` 會讓容器程序使用主機目前使用者的 UID/GID,`HOME` 則確保 ChatLab 的系統目錄仍是 `/home/node/.chatlab`。對於目前使用者 UID/GID 不是 1000 的 Linux 主機,這兩個參數是必要的。主機的 `~/.chatlab` 對應容器內的 `/home/node/.chatlab`,`~/Downloads` 對應容器內可寫的下載目錄;`CHATLAB_DATA_DIR` 將預設使用者資料固定到容器可存取的 `/home/node/.chatlab/data`,避免主機 `config.toml` 中的絕對路徑在容器內失效。
|
||||
|
||||
使用這組指令後,兩種切換都不需要複製資料:
|
||||
|
||||
- 先使用 Docker,之後安裝 Desktop 或本機 CLI:Desktop / CLI 會繼續讀取主機的 `~/.chatlab`。
|
||||
- 已經使用 Desktop 或本機 CLI,之後啟動 Docker:Docker 會直接讀取原有的設定、聊天資料庫和 AI 資料。
|
||||
|
||||
### 使用獨立 Docker 資料
|
||||
|
||||
在伺服器上部署,或明確不想與主機上的 ChatLab 共用資料時,可以使用 Docker named volume:
|
||||
|
||||
```bash
|
||||
docker run --name chatlab \
|
||||
-p 127.0.0.1:3110:3110 \
|
||||
@@ -19,9 +63,27 @@ docker run --name chatlab \
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
容器啟動後,開啟 <http://127.0.0.1:3110/>。
|
||||
此資料卷會保留容器內的系統狀態與使用者資料,但 Desktop 和主機 CLI **不會**自動看到其中的資料。替換或升級容器時,請保留 `chatlab-data` 資料卷。
|
||||
|
||||
映像使用非特權 `node` 使用者執行。此資料卷會保留 `/home/node/.chatlab` 下的系統狀態與使用者資料。替換或升級容器時,請保留此資料卷。
|
||||
### 自訂使用者資料目錄
|
||||
|
||||
如果 Desktop / CLI 已將聊天資料庫移到 `~/.chatlab` 以外,還需要另外掛載該目錄,並讓環境變數指向對應的容器路徑:
|
||||
|
||||
```bash
|
||||
docker run --name chatlab \
|
||||
-p 127.0.0.1:3110:3110 \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
--mount type=bind,source="/absolute/path/to/chatlab-data",target=/chatlab-data \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/chatlab-data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest
|
||||
```
|
||||
|
||||
請將 `/absolute/path/to/chatlab-data` 替換為主機上的真實使用者資料目錄。系統資料仍透過 `~/.chatlab` 掛載。由於 `CHATLAB_DATA_DIR` 的優先順序最高,Docker 的資料目錄應透過掛載和環境變數調整,而不是在儲存管理頁面中切換。
|
||||
|
||||
相同版本的 Desktop、CLI 和 Docker 可以共用資料庫。切換資料目錄、執行遷移或跨版本使用前,建議先停止其他 ChatLab 執行個體;如果舊版本無法安全讀取已經升級的資料目錄,ChatLab 會透過相容性閘門拒絕啟動。
|
||||
|
||||
## 服務選項
|
||||
|
||||
@@ -48,7 +110,11 @@ Docker 參數會替換完整的預設命令。加入服務選項時,需要視
|
||||
```bash
|
||||
docker run --rm \
|
||||
-p 127.0.0.1:8080:8080 \
|
||||
-v chatlab-data:/home/node/.chatlab \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest \
|
||||
start --port 8080 --host 0.0.0.0 --headless --no-open
|
||||
```
|
||||
@@ -58,8 +124,13 @@ docker run --rm \
|
||||
```bash
|
||||
docker run --rm ghcr.io/chatlab/chatlab-cli:latest --version
|
||||
docker run --rm ghcr.io/chatlab/chatlab-cli:latest formats
|
||||
docker run --rm -v chatlab-data:/home/node/.chatlab \
|
||||
ghcr.io/chatlab/chatlab-cli:latest sessions --format json
|
||||
docker run --rm \
|
||||
--user "$(id -u):$(id -g)" \
|
||||
--mount type=bind,source="$HOME/.chatlab",target=/home/node/.chatlab \
|
||||
--mount type=bind,source="$HOME/Downloads",target=/home/node/Downloads \
|
||||
-e HOME=/home/node \
|
||||
-e CHATLAB_DATA_DIR=/home/node/.chatlab/data \
|
||||
ghcr.io/chatlab/chatlab-cli:latest sessions list --format json
|
||||
```
|
||||
|
||||
## 環境變數
|
||||
@@ -98,15 +169,32 @@ Bearer Token、無介面模式、Web UI 驗證與瀏覽器開啟行為透過對
|
||||
|
||||
## Docker Compose
|
||||
|
||||
先在 Compose 檔案旁建立未追蹤的 `.env`:
|
||||
|
||||
```dotenv
|
||||
CHATLAB_HOST_DIR=/absolute/path/to/.chatlab
|
||||
CHATLAB_DOWNLOADS_DIR=/absolute/path/to/Downloads
|
||||
CHATLAB_UID=1000
|
||||
CHATLAB_GID=1000
|
||||
CHATLAB_TOKEN=replace-with-a-secret-token
|
||||
```
|
||||
|
||||
將 `CHATLAB_HOST_DIR` 替換為主機 `~/.chatlab` 的絕對路徑,並將 `CHATLAB_DOWNLOADS_DIR` 設定為已存在且可寫入的匯出與截圖目錄,例如主機的 `~/Downloads`。在 macOS 和 Linux 上,還需要將 `CHATLAB_UID`、`CHATLAB_GID` 分別替換為 `id -u`、`id -g` 的輸出;Windows Docker Desktop 可以保留 `1000`。
|
||||
|
||||
```yaml
|
||||
services:
|
||||
chatlab:
|
||||
image: ghcr.io/chatlab/chatlab-cli:latest
|
||||
restart: unless-stopped
|
||||
user: "${CHATLAB_UID:-1000}:${CHATLAB_GID:-1000}"
|
||||
ports:
|
||||
- "127.0.0.1:3110:3110"
|
||||
environment:
|
||||
HOME: /home/node
|
||||
CHATLAB_DATA_DIR: /home/node/.chatlab/data
|
||||
volumes:
|
||||
- chatlab-data:/home/node/.chatlab
|
||||
- "${CHATLAB_HOST_DIR:?set CHATLAB_HOST_DIR in the Compose environment}:/home/node/.chatlab"
|
||||
- "${CHATLAB_DOWNLOADS_DIR:?set CHATLAB_DOWNLOADS_DIR in the Compose environment}:/home/node/Downloads"
|
||||
command:
|
||||
- start
|
||||
- --port
|
||||
@@ -117,12 +205,9 @@ services:
|
||||
- ${CHATLAB_TOKEN:?set CHATLAB_TOKEN in the Compose environment}
|
||||
- --require-auth
|
||||
- --no-open
|
||||
|
||||
volumes:
|
||||
chatlab-data:
|
||||
```
|
||||
|
||||
`CHATLAB_TOKEN` 由 Docker Compose 插值後作為 `--token` 的值傳給 ChatLab,並不是 ChatLab 環境變數。請將它儲存在密鑰儲存或未追蹤的 `.env` 檔案中。
|
||||
`CHATLAB_TOKEN` 由 Docker Compose 插值後作為 `--token` 的值傳給 ChatLab,並不是 ChatLab 環境變數。請將它儲存在密鑰儲存或未追蹤的 `.env` 檔案中。如果需要完全獨立的伺服器資料,請改用上文「使用獨立 Docker 資料」中的 named volume。
|
||||
|
||||
## 多架構映像
|
||||
|
||||
|
||||
Reference in new issue
Block a user