Files
integral-shop/deploy/docker/README.md
2026-05-29 09:19:30 +08:00

120 lines
3.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Docker 部署 — 快速上手
> 详细方案见仓库根目录的 `DOCKER_DEPLOY.md`。本文件只列必要操作。
## 已提供的项目化部署目录
| 项目 | 步骤一 | 步骤二 |
|-----|------|------|
| `czleilei240` 参考模板 | `deploy/docker/step1-integral` | `deploy/docker/step2-single-shop` |
| `byhlc112` | `deploy/docker/step1-integral-byhlc112` | `deploy/docker/step2-single-shop-byhlc112` |
## 1. 准备环境变量
```bash
cd deploy/docker
cp .env.example .env
$EDITOR .env # 填入 RDS / Redis / 域名 等
cp integral-resell/.env.template integral-resell/.env
$EDITOR integral-resell/.env # 积分商城 Webman 后端配置
```
## 2. 阿里云 RDS 初始化
在 RDS 控制台新建:
- 积分商城库(默认名 `yangtangyoupin`)→ 导入 `db/yangtangyoupin.sql`
- 寄卖商城库(默认同上)→ 导入 `db/shop22-v2.sql`(或与生产对齐的 `db/jjy153-mysql.sql`
把 Docker 主机出口 IP 加入 RDS 白名单。
## 3. 构建并启动
```bash
# 一次性构建所有镜像(首次 5-15 分钟,含 Maven & Node 拉依赖)
docker compose build
# 后台启动全部服务
docker compose up -d
# 查看状态
docker compose ps
docker compose logs -f single-admin-api
docker compose logs -f single-front-api
docker compose logs -f integral-houtai
```
## 4. 验证
| URL | 期望 |
|-----|------|
| `http://<host>:18080/` | 积分商城 H5 首页 |
| `http://<host>:18080/api/...` | 转发到 integral-houtai |
| `http://<host>:18081/` | 寄卖管理后台登录页 |
| `http://<host>:18082/` | 寄卖用户端 H5 |
## 5. 常用运维
```bash
docker compose restart single-admin-api
docker compose build --no-cache single-front-api && docker compose up -d single-front-api
docker compose exec single-admin-api sh
docker compose down # 不删卷
docker compose down -v # 连卷一并删除(**慎用**
```
## 6. 备份卷
```bash
# 在 docker host 上运行
for v in integral-upload single-images redis-data; do
docker run --rm -v $v:/d -v $(pwd):/b alpine \
tar czf /b/${v}-$(date +%F).tgz -C /d .
done
```
## 7. "fast" 模式(跳过前端构建,使用源码已有 dist
如果源码目录里 `backend-adminend/dist``single_uniapp22miao/unpackage/dist/build/` 已经是最新构建产物,可加速:
```bash
docker compose build --build-arg=BUILDKIT_INLINE_CACHE=1 \
--target fast single-admin-web single-h5
```
## 8. 切换为外部 Redis
`.env``REDIS_HOST` 改为外部地址、注释 `docker-compose.yml` 中的 `redis:` 服务即可。Spring Boot 与 Webman 都通过环境变量读取 Redis 地址。
## 9. 远端一键部署116.62.83.240
```bash
cd scripts
cp server.env.example server.env # 已预填 116.62.83.240 / root / A@123456
# 首次(推荐):把密码登录换成 SSH key
ssh-copy-id root@116.62.83.240
# 然后把 server.env 里的 SSHPASS 行注释掉
# 同步代码并启动
./sync-to-server.sh up
# 同步完成后,若是首次部署还需要先在远端填写 .env
./bootstrap-remote-env.sh
./remote-up.sh ssh
# 远端cd /root/integral-shop/deploy/docker
# vim .env
# vim integral-resell/.env
# 编辑完退出后:
./remote-up.sh up
# 日常运维(本机执行,不用登录服务器)
./remote-up.sh ps
./remote-up.sh logs single-admin-api
./remote-up.sh restart single-front-api
./remote-up.sh build single-admin-web
```
> 用密码模式需要先 `brew install hudochenkov/sshpass/sshpass`macOS
> 用 SSH key 模式则任何依赖都不需要。