Files
MyTool/docker/README.md

76 lines
2.1 KiB
Markdown
Raw 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.
# MangTool Docker 部署
前后端单容器部署:拉代码后进入 `docker` 目录,执行启动脚本即可。
## 环境要求
- Docker
- Docker Composev2 推荐:`docker compose`
## 部署步骤
### 1. 拉取代码
```bash
git clone <仓库地址>
cd MyTool
```
### 2. 启动服务
**Linux / macOS**
```bash
cd docker
chmod +x start.sh
./start.sh
```
**Windows**
在资源管理器中进入 `docker` 目录,双击运行 `start.bat`;或在终端执行:
```cmd
cd docker
start.bat
```
或直接使用 docker compose
```bash
cd docker
docker compose up -d --build
```
### 3. 访问应用
浏览器打开:**http://localhost:8080**
前端与后端由同一服务提供,无需单独配置 API 地址。
## 常用命令
| 操作 | 命令 |
|------------|------------------------------|
| 后台启动 | `docker compose up -d --build` |
| 查看日志 | `docker compose logs -f` |
| 停止并删除 | `docker compose down` |
| 仅重新构建 | `docker compose build --no-cache` |
| 查看状态 | `docker compose ps` |
| 健康检查 | `docker compose exec mangtool wget -q -O- http://localhost:8080/api/health` |
## 端口与数据
- **端口**:宿主机 `8080` 映射容器 `8080`,可在 `docker-compose.yml` 中修改左侧端口,例如 `"8888:8080"`
- **数据**:工具读写路径在容器内;若需挂载宿主机目录(如音乐库、输入输出目录),在 `docker-compose.yml` 中取消 `volumes` 注释并改为实际路径。
## 构建说明
- **Dockerfile**:多阶段构建
1. 使用 Node 20 构建前端Vite产出到 `dist`
2. 使用 Maven + JDK 8 构建后端,并将前端 `dist` 拷贝到 `src/main/resources/static`
3. 运行阶段使用 `eclipse-temurin:8-jre-alpine`,仅运行打包好的 Spring Boot jar
4. 内置健康检查(每 30 秒检查 `/api/health` 端点)
- 生产环境前端 API/WebSocket 使用相对路径,与后端同源,无需再配 CORS。
- 已配置 `.dockerignore` 优化构建上下文,加快构建速度。