fix: podman can't deploy

This commit is contained in:
2026-09-21 13:17:14 +08:00
parent 931d3ee1b7
commit 3fdce3ce94
8 changed files with 165 additions and 11 deletions

View File

@@ -48,7 +48,7 @@ pnpm build # 生产构建(vue-tsc 类型检查 + vite build)
```bash
cp .env.example .env # 可选:按需修改端口/密码/JWT 密钥
docker compose up -d --build # 构建并启动 mariadb + backend + frontend
# 前端:http://localhost (Nginx 托管静态资源并反代 /api)
# 前端:http://localhost:8088 (Nginx 托管静态资源并反代 /api)
# 后端:http://localhost:8080
docker compose ps # 查看健康状态
docker compose down # 停止容器,保留数据库数据卷
@@ -57,10 +57,53 @@ docker compose down -v # 停止并清空数据库(下次启动重建
- 编排:`mariadb:11.4`(数据持久化到命名卷)+ 后端多阶段构建镜像(JRE 21,非 root 运行)+ Nginx 前端镜像
- 三个服务均配置健康检查,后端与前端会等待上游就绪后再启动
- 国内加速:后端构建自动使用**阿里云 Maven 镜像**(`docker/maven-settings.xml`),
前端使用 **npmmirror**(淘宝 npm 镜像);如需走官方源:
`docker build --build-arg MAVEN_MIRROR=false .`、`docker build --build-arg NPM_REGISTRY=https://registry.npmjs.org ./frontend`
- 可用环境变量(见 `.env.example`):`WEB_PORT`(默认 80)、`BACKEND_PORT`(默认 8080)、
`DB_NAME` / `DB_USER` / `DB_PASSWORD` / `DB_ROOT_PASSWORD`、`LAB_JWT_SECRET`、`JAVA_OPTS`
### 4. 演示账号
### 4. Podman 部署
Podman 的 compose 实现与 Docker Compose 在「镜像名/容器名解析」上存在差异,
直接 `podman compose up -d` 可能出现以下报错:
```
Error: short-name "lab-reservation_backend" did not resolve to an alias ...
Error: "lab-backend" is not a valid container, cannot be used as a dependency ...
```
原因是 compose 未先构建本地镜像,Podman 便把 `lab-reservation_backend` 当作待拉取的短名镜像,
而系统未配置 `unqualified-search-registries`。**先显式构建镜像即可解决**:
```bash
./scripts/podman-deploy.sh up # 一键:构建镜像 -> 启动 -> 健康检查 -> 打印访问地址
./scripts/podman-deploy.sh down # 停止(保留数据库数据卷)
./scripts/podman-deploy.sh down-v # 停止并清空数据库
./scripts/podman-deploy.sh logs # 查看日志
```
手动等价步骤:
```bash
podman build -t lab-backend:latest .
podman build -t lab-frontend:latest ./frontend
podman compose up -d # 或 podman-compose up -d
```
Podman 注意事项:
- **端口**:前端默认映射到 `8088`(rootless Podman 无法绑定 80 等特权端口),
如需 80 可 `WEB_PORT=80 ./scripts/podman-deploy.sh up`,或将
`net.ipv4.ip_unprivileged_port_start=0` 写入 `/etc/sysctl.d/` 后 `sysctl --system`
- **短名镜像**:本项目所有基础镜像已写成全限定名(`docker.io/library/...`)。
若自行添加镜像,建议同样全限定,或在
`~/.config/containers/registries.conf` 配置 `unqualified-search-registries = ["docker.io"]`
- **旧版 podman-compose**:若提示不支持 `depends_on.condition`,请升级到 1.0.6+,
或先 `podman-compose up -d mariadb`,等数据库健康后再 `podman-compose up -d backend frontend`
- **SELinux(Fedora/RHEL)**:本项目只使用命名卷,无需额外 `:Z` 标记;如自定义 bind mount 请自行加 `:Z`
### 5. 演示账号
| 账号 | 密码 | 角色 | 典型能力 |
| --- | --- | --- | --- |
@@ -140,6 +183,7 @@ mvn verify # 运行全部测试并执行 JaCoCo 覆盖率门禁
├── Dockerfile # 后端多阶段构建镜像
├── docker-compose.yml # mariadb + backend + frontend 一键编排
├── .env.example # 部署环境变量示例(复制为 .env 使用)
├── scripts/podman-deploy.sh # Podman 一键部署脚本
└── docs/design.md # 需求分析与详细设计
```