# 资金服务平台 Docker 部署指南 > **版本**: v1.0 > **更新日期**: 2026-02-19 --- ## 一、环境要求 | 软件 | 版本 | 说明 | |------|------|------| | Docker | 20.10+ | 容器运行环境 | | Docker Compose | 2.0+ | 容器编排工具 | | Maven | 3.8+ | Java 构建工具 | | JDK | 21 | Java 运行环境 | --- ## 二、Docker 镜像源配置 国内网络访问 Docker Hub 较慢,建议配置镜像源: ```bash # 创建配置文件 sudo tee /etc/docker/daemon.json <<'EOF' { "registry-mirrors": [ "https://docker.m.daocloud.io", "https://dockerhub.icu", "https://hub.rat.dev" ] } EOF # 重启 Docker 服务 sudo systemctl restart docker # 验证配置 docker info | grep -A 3 "Registry Mirrors" ``` --- ## 三、镜像构建 ### 3.1 使用构建脚本(推荐) ```bash cd /home/along/MyCode/wanjiabuluo/fundplatform # 查看帮助 ./scripts/docker-build.sh help # 检查 Docker 环境 ./scripts/docker-build.sh check # 配置镜像源(需要 sudo) ./scripts/docker-build.sh mirror # 构建单个模块 ./scripts/docker-build.sh build fund-sys # 构建所有模块 ./scripts/docker-build.sh build-all # 使用 docker-compose 构建 ./scripts/docker-build.sh compose # 清理未使用的镜像 ./scripts/docker-build.sh clean ``` ### 3.2 手动构建单个模块 ```bash # 构建命令格式 docker build --build-arg MODULE=<模块名> -t <镜像名>:<标签> . # 示例:构建 fund-sys docker build --build-arg MODULE=fund-sys -t fund-sys:latest . # 示例:构建 fund-gateway docker build --build-arg MODULE=fund-gateway -t fund-gateway:latest . ``` ### 3.3 构建所有模块 ```bash # 循环构建所有模块 for module in fund-gateway fund-sys fund-cust fund-proj fund-req fund-exp fund-receipt fund-report fund-file; do echo "构建 $module..." docker build --build-arg MODULE=$module -t $module:latest . done # 或使用 docker-compose docker-compose build ``` --- ## 四、服务端口规划 | 服务 | 容器端口 | 主机端口 | 说明 | |------|----------|----------|------| | fund-gateway | 8000 | 8000 | API 网关 | | fund-sys | 8100 | 8100 | 系统服务 | | fund-cust | 8200 | 8200 | 客户服务 | | fund-proj | 8300 | 8300 | 项目服务 | | fund-req | 8400 | 8400 | 需求工单服务 | | fund-exp | 8500 | 8500 | 支出服务 | | fund-receipt | 8600 | 8600 | 收款服务 | | fund-report | 8700 | 8700 | 报表服务 | | fund-file | 8800 | 8800 | 文件服务 | | mysql | 3306 | 3306 | MySQL 数据库 | | redis | 6379 | 6379 | Redis 缓存 | | nacos | 8848 | 8848 | Nacos 注册中心 | | prometheus | 9090 | 9090 | Prometheus 监控 | | grafana | 3000 | 3000 | Grafana 可视化 | --- ## 五、启动服务 ### 5.1 启动基础设施 ```bash # 仅启动 MySQL、Redis、Nacos docker-compose up -d mysql redis nacos # 查看服务状态 docker-compose ps # 查看日志 docker-compose logs -f nacos ``` ### 5.2 启动所有服务 ```bash # 启动所有服务 docker-compose up -d # 查看服务状态 docker-compose ps # 查看所有服务日志 docker-compose logs -f # 查看单个服务日志 docker-compose logs -f fund-sys ``` ### 5.3 分步启动 ```bash # 1. 启动基础设施 docker-compose up -d mysql redis nacos # 2. 等待 Nacos 就绪(约 60 秒) sleep 60 # 3. 启动网关 docker-compose up -d gateway # 4. 启动业务服务 docker-compose up -d fund-sys fund-cust fund-proj fund-req fund-exp fund-receipt fund-report fund-file # 5. 启动监控 docker-compose up -d prometheus grafana ``` --- ## 六、停止服务 ```bash # 停止所有服务 docker-compose down # 停止并删除数据卷 docker-compose down -v # 停止单个服务 docker-compose stop fund-sys # 重启单个服务 docker-compose restart fund-sys ``` --- ## 七、访问地址 | 服务 | 地址 | 用户名/密码 | |------|------|-------------| | Nacos 控制台 | http://localhost:8848/nacos | nacos / nacos | | Grafana | http://localhost:3000 | admin / admin123 | | Prometheus | http://localhost:9090 | - | | API 网关 | http://localhost:8000 | - | | 健康检查 | http://localhost:8100/actuator/health | - | | Prometheus 指标 | http://localhost:8100/actuator/prometheus | - | --- ## 八、常用命令 ### 8.1 容器管理 ```bash # 查看运行中的容器 docker ps # 查看所有容器(包括已停止) docker ps -a # 进入容器 docker exec -it fund-sys sh # 查看容器日志 docker logs -f fund-sys # 查看容器资源使用 docker stats fund-sys ``` ### 8.2 镜像管理 ```bash # 查看本地镜像 docker images # 删除镜像 docker rmi fund-sys:latest # 清理未使用的镜像 docker image prune -f # 导出镜像 docker save -o fund-sys.tar fund-sys:latest # 导入镜像 docker load -i fund-sys.tar ``` ### 8.3 数据卷管理 ```bash # 查看数据卷 docker volume ls # 删除数据卷 docker volume rm fund-mysql-data # 清理未使用的数据卷 docker volume prune ``` --- ## 九、环境变量配置 在 `docker-compose.yml` 中通过环境变量配置服务: ```yaml environment: # 服务端口 SERVER_PORT: 8100 # Spring Profile SPRING_PROFILES_ACTIVE: docker # Nacos 配置 NACOS_SERVER_ADDR: nacos:8848 NACOS_USERNAME: nacos NACOS_PASSWORD: nacos # MySQL 配置 MYSQL_HOST: mysql MYSQL_PORT: 3306 MYSQL_DB: fund_platform MYSQL_USER: root MYSQL_PASSWORD: root123 # Redis 配置 REDIS_HOST: redis REDIS_PORT: 6379 # JVM 参数 JAVA_OPTS: -Xms256m -Xmx512m -XX:+UseG1GC ``` --- ## 十、故障排查 ### 10.1 服务启动失败 ```bash # 查看服务日志 docker-compose logs fund-sys # 查看容器状态 docker inspect fund-sys # 检查网络 docker network inspect fund-network ``` ### 10.2 无法连接 Nacos ```bash # 检查 Nacos 是否就绪 curl http://localhost:8848/nacos/v1/console/health/readiness # 检查服务注册情况 curl http://localhost:8848/nacos/v1/ns/instance/list?serviceName=fund-sys ``` ### 10.3 数据库连接失败 ```bash # 进入 MySQL 容器 docker exec -it fund-mysql mysql -uroot -proot123 # 检查数据库 SHOW DATABASES; USE fund_platform; SHOW TABLES; ``` --- ## 十一、生产环境建议 1. **修改默认密码**:修改 MySQL、Redis、Nacos、Grafana 的默认密码 2. **配置 HTTPS**:使用 Nginx 反向代理并配置 SSL 证书 3. **资源限制**:在 docker-compose.yml 中配置 CPU 和内存限制 4. **日志持久化**:将日志挂载到宿主机 5. **数据备份**:定期备份 MySQL 数据 6. **监控告警**:配置 Prometheus 告警规则