一、 环境准备
在 Docker 共享文件夹下创建以下目录结构,用于持久化存储数据:
/Docker/affine
/config(配置文件)
/postgres(数据库数据)
/postgresql(备用,部分配置可能用到)
/storage(上传的资源文件)
二、 创建环境变量文件 (.env)
在 /Docker/affine 文件夹下创建一个名为 .env 的文件,填入以下内容(注意替换你的数据库用户名和密码):
代码段
# 数据库与存储路径
DB_DATA_LOCATION=./postgres
UPLOAD_LOCATION=./storage
CONFIG_LOCATION=./config
# 数据库配置(请自行修改 username 和 password)
DB_USERNAME=your_username
DB_PASSWORD=your_password
DB_DATABASE=affine
三、 编写 Docker Compose 配置
在飞牛NAS的 Docker 管理界面中,新增一个 Compose 项目,命名为 affine,选择刚才创建的目录,并填入以下代码:
YAML
name: affine
services:
affine:
image: ghcr.io/toeverything/affine:${AFFINE_REVISION:-stable}
container_name: affine_server
ports:
- '3010:3010' # 冒号左侧的 3010 可修改为你想用的端口
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
affine_migration:
condition: service_completed_successfully
volumes:
- /vol1/1000/Docker/affine/storage:/root/.affine/storage
- /vol1/1000/Docker/affine/config:/root/.affine/config
env_file:
- .env
environment:
- REDIS_SERVER_HOST=redis
- DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
- AFFINE_INDEXER_ENABLED=false
restart: unless-stopped
affine_migration:
image: ghcr.io/toeverything/affine:${AFFINE_REVISION:-stable}
container_name: affine_migration_default
volumes:
- /vol1/1000/Docker/affine/storage:/root/.affine/storage
- /vol1/1000/Docker/affine/config:/root/.affine/config
command: ['sh', '-c', 'node ./scripts/self-host-predeploy.js']
env_file:
- .env
environment:
- REDIS_SERVER_HOST=redis
- DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
- AFFINE_INDEXER_ENABLED=false
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
redis:
image: redis
container_name: affine_redis
healthcheck:
test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
postgres:
image: pgvector/pgvector:pg16
container_name: affine_postgres
volumes:
- /vol1/1000/Docker/affine/postgres:/var/lib/postgresql/data
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_DATABASE:-affine}
POSTGRES_INITDB_ARGS: '--data-checksums'
POSTGRES_HOST_AUTH_METHOD: trust
healthcheck:
test: ['CMD', 'pg_isready', '-U', "${DB_USERNAME}", '-d', "${DB_DATABASE:-affine}"]
interval: 10s
timeout: 5s
retries: 5
restart: unless-stopped
注意: 请根据你实际的硬盘卷路径(如 /vol1/1000/...)修改 volumes 下的路径。
四、 启动与初始化
点击“构建”并启动。
启动后会有 4 个容器,其中 affine_migration_default