nex_buddy/docker/README.md

59 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Docker 部署
## 文件
| 文件 | 用途 |
|---|---|
| `docker/Dockerfile.api` | FastAPI 镜像(多阶段构建) |
| `docker/Dockerfile.web` | 前端构建 + Nginx 镜像 |
| `docker/nginx.conf` | 容器内 Nginx:静态文件 + `/api`、`/device` 反代 |
| `docker/api-entrypoint.sh` | 启动前创建数据目录、补 `regions.json`、执行迁移 |
| `docker-compose.yml` | API + Web;数据库/Redis 使用 `.env` 中的外部实例 |
| `docker-compose.full.yml` | 可选覆盖:同时启动 PostgreSQL + Redis |
## 国内下载加速
构建参数默认已经改成国内源,也可以在 `.env` 或命令行覆盖:
| 参数 | 默认值 | 用途 |
|---|---|---|
| `PIP_INDEX_URL` | `https://pypi.tuna.tsinghua.edu.cn/simple` | pip 包 |
| `APT_MIRROR` | `mirrors.tuna.tsinghua.edu.cn` | Debian apt(仅构建阶段) |
| `NPM_REGISTRY` | `https://registry.npmmirror.com` | npm 包 |
```bash
# 临时换源构建
PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ \
APT_MIRROR=mirrors.aliyun.com \
NPM_REGISTRY=https://registry.npmmirror.com \
docker compose build
```
Docker 镜像本身不在这里配置;如果 `docker pull` 慢,在宿主机
`/etc/docker/daemon.json` 配镜像加速,然后重启 Docker:
```json
{
"registry-mirrors": ["https://docker.m.daocloud.io"]
}
```
镜像加速地址会变化,以当前可用的服务为准。
## 数据目录
容器内固定使用 `/app/data`,Compose 默认把宿主机 `./data` 挂进去:
```yaml
volumes:
- "${NEX_BUDDY_DATA_DIR:-./data}:/app/data"
```
所以在 `.env` 里写绝对路径即可把资源放到独立磁盘:
```bash
NEX_BUDDY_DATA_DIR=/srv/nex_buddy/data
```
首次挂载空目录时,entrypoint 会把镜像内的 `regions.json` 复制进去;媒体和固件目录会自动创建。