From a35b3c82627cbe0fd8cc25b8843ff34a2224b7ce Mon Sep 17 00:00:00 2001 From: Lan Date: Sat, 24 Jan 2026 11:58:23 +0800 Subject: [PATCH] feat: update Docker configuration and add environment variable documentation --- Dockerfile | 15 +++++++++- docs/guide/getting-started.md | 55 ++++++++++++++++++++++++++++++++++- readme.md | 28 ++++++++++++++++-- readme_en.md | 38 +++++++++++++++++++----- 4 files changed, 125 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 004d2c8..4d63c20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,19 @@ COPY --from=frontend-builder /build/fronted-2023/dist ./themes/2023 # 安装 Python 依赖 RUN pip install --no-cache-dir -r requirements.txt +# 环境变量配置 +ENV HOST="::" \ + PORT=12345 \ + WORKERS=4 \ + LOG_LEVEL="info" + EXPOSE 12345 -CMD ["python", "main.py"] \ No newline at end of file +# 生产环境启动命令 +CMD uvicorn main:app \ + --host $HOST \ + --port $PORT \ + --workers $WORKERS \ + --log-level $LOG_LEVEL \ + --proxy-headers \ + --forwarded-allow-ips "*" \ No newline at end of file diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index fecc86d..b09d069 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -17,8 +17,61 @@ FileCodeBox 是一个简单高效的文件分享工具,支持文件临时中 ### Docker 部署(推荐) +#### 快速启动 + ```bash -docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:beta +docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:latest +``` + +#### Docker Compose + +```yml +version: "3" +services: + file-code-box: + image: lanol/filecodebox:latest + volumes: + - fcb-data:/app/data:rw + restart: unless-stopped + ports: + - "12345:12345" + environment: + - WORKERS=4 + - LOG_LEVEL=info +volumes: + fcb-data: + external: false +``` + +#### 环境变量 + +| 变量 | 默认值 | 说明 | +|------|--------|------| +| `HOST` | `::` | 监听地址,支持 IPv4/IPv6 双栈 | +| `PORT` | `12345` | 服务端口 | +| `WORKERS` | `4` | 工作进程数,建议设置为 CPU 核心数 | +| `LOG_LEVEL` | `info` | 日志级别:debug/info/warning/error | + +#### 自定义配置示例 + +```bash +docker run -d --restart=always \ + -p 12345:12345 \ + -v /opt/FileCodeBox/:/app/data \ + -e WORKERS=8 \ + -e LOG_LEVEL=warning \ + --name filecodebox \ + lanol/filecodebox:latest +``` + +### 配置反向代理(Nginx) + +```nginx +location / { + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://localhost:12345; +} ``` ### 手动部署 diff --git a/readme.md b/readme.md index a8bcc60..2061630 100644 --- a/readme.md +++ b/readme.md @@ -193,7 +193,7 @@ FileCodeBox 是一个基于 FastAPI + Vue3 开发的轻量级文件分享工具 #### Docker CLI ```bash -docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:beta +docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:latest ``` #### Docker Compose @@ -208,11 +208,35 @@ services: restart: unless-stopped ports: - "12345:12345" + environment: + - WORKERS=4 + - LOG_LEVEL=info volumes: fcb-data: external: false ``` +#### 环境变量 + +| 变量 | 默认值 | 说明 | +|------|--------|------| +| `HOST` | `::` | 监听地址,支持 IPv4/IPv6 双栈 | +| `PORT` | `12345` | 服务端口 | +| `WORKERS` | `4` | 工作进程数,建议设置为 CPU 核心数 | +| `LOG_LEVEL` | `info` | 日志级别:debug/info/warning/error | + +**自定义配置示例:** + +```bash +docker run -d --restart=always \ + -p 12345:12345 \ + -v /opt/FileCodeBox/:/app/data \ + -e WORKERS=8 \ + -e LOG_LEVEL=warning \ + --name filecodebox \ + lanol/filecodebox:latest +``` + ### 配置反向代理(Nginx示例) 请注意,必须添加以下配置来确保正确处理客户端IP和代理请求: @@ -221,7 +245,7 @@ volumes: location / { proxy_set_header X-Real-IP $remote_addr; # 设置真实客户端IP proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass http://localhost:12345; + proxy_pass http://localhost:12345; } ``` diff --git a/readme_en.md b/readme_en.md index 244219e..c93661d 100644 --- a/readme_en.md +++ b/readme_en.md @@ -189,14 +189,14 @@ Command-line download #### Docker CLI ```bash -docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:beta +docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --name filecodebox lanol/filecodebox:latest ``` #### Docker Compose -```ymlfix +```yml version: "3" -services:s +services: file-code-box: image: lanol/filecodebox:latest volumes: @@ -204,20 +204,44 @@ services:s restart: unless-stopped ports: - "12345:12345" + environment: + - WORKERS=4 + - LOG_LEVEL=info volumes: fcb-data: external: false ``` -### Configure reverse proxy (Nginx example) +#### Environment Variables + +| Variable | Default | Description | +|----------|---------|-------------| +| `HOST` | `::` | Listen address, supports IPv4/IPv6 dual-stack | +| `PORT` | `12345` | Service port | +| `WORKERS` | `4` | Number of worker processes, recommended to set to CPU cores | +| `LOG_LEVEL` | `info` | Log level: debug/info/warning/error | + +**Custom configuration example:** + +```bash +docker run -d --restart=always \ + -p 12345:12345 \ + -v /opt/FileCodeBox/:/app/data \ + -e WORKERS=8 \ + -e LOG_LEVEL=warning \ + --name filecodebox \ + lanol/filecodebox:latest +``` + +### Configure Reverse Proxy (Nginx Example) Please note that the following configurations must be added to ensure proper handling of client IP and proxy requests: ```nginx location / { -proxy_set_header X-Real-IP $remote_addr; #Set real client IP -proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; -proxy_pass http://localhost:12345 ; + proxy_set_header X-Real-IP $remote_addr; # Set real client IP + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_pass http://localhost:12345; } ```