Files
kenaito-conf/README_DOCKERFILE.md
T
odboy 182765e4a0 feat: 新增 Spring Boot 3 客户端 SDK 及 demo
- 新增 kenaito-conf-springboot3-client,支持配置拉取、增量同步、@Value/@ConfigurationProperties 动态刷新和本地缓存

- 新增 kenaito-conf-springboot3-client-demo(端口 8084)及 Dockerfile.springboot3

- 完善中英文 README、Docker 部署文档,修正 Spring Boot 2 客户端配置键名与 demo 端口说明

- 修复增量同步将服务端 code=0 成功响应误判为错误的问题
2026-08-22 21:02:15 +08:00

316 lines
9.3 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.
# Kenaito Config Center 客户端 Docker 部署指南
本文档说明如何使用 Dockerfile 构建和测试各语言客户端 demo。
所有命令均在项目根目录执行。
## Go 客户端
```bash
docker build -f Dockerfile.go -t kenaito-conf-go-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-golang-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-golang-demo
```
## Node.js 客户端
```bash
docker build -f Dockerfile.nodejs -t kenaito-conf-nodejs-demo .
# linux or mac
docker run -d --rm --name nodejs-demo \
-p 8083:8083 \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-nodejs-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-nodejs-demo
# 查看日志
docker logs -f nodejs-demo
# 测试接口
curl http://localhost:8083/
curl http://localhost:8083/health
# 停止
docker stop nodejs-demo
```
## Python 客户端
```bash
docker build -f Dockerfile.python -t kenaito-conf-python-demo .
# linux or mac
docker run -d --rm --name python-demo \
-p 8082:8082 \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-python-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-python-demo
# 查看日志
docker logs -f python-demo
# 测试接口
curl http://localhost:8082/
curl http://localhost:8082/health
# 停止
docker stop python-demo
```
## .NET 客户端
```bash
docker build -f Dockerfile.dotnet -t kenaito-conf-dotnet-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-dotnet-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-dotnet-demo
```
## Perl 客户端
```bash
docker build -f Dockerfile.perl -t kenaito-conf-perl-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-perl-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-perl-demo
```
## Lua 客户端
```bash
docker build -f Dockerfile.lua -t kenaito-conf-lua-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-lua-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-lua-demo
```
## PHP 客户端
```bash
docker build -f Dockerfile.php -t kenaito-conf-php-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-php-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-php-demo
```
## Spring Boot 2 客户端
```bash
docker build -f Dockerfile.springboot2 -t kenaito-conf-springboot2-demo .
# linux or mac
docker run -d --rm --name springboot2-demo \
-p 8081:8081 \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-springboot2-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-springboot2-demo
# 查看日志
docker logs -f springboot2-demo
# 测试接口
curl http://localhost:8081/
curl http://localhost:8081/health
# 停止
docker stop springboot2-demo
```
## Spring Boot 3 客户端
Spring Boot 3 客户端要求 JDK 17+,Demo 默认监听 `8084`。构建阶段使用 Maven 3 + JDK 21 镜像编译,运行阶段使用 `eclipse-temurin:17-jre`。
```bash
docker build -f Dockerfile.springboot3 -t kenaito-conf-springboot3-demo .
# linux or mac
docker run -d --rm --name springboot3-demo \
-p 8084:8084 \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-springboot3-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-springboot3-demo
# 查看日志
docker logs -f springboot3-demo
# 测试接口
curl http://localhost:8084/config
curl http://localhost:8084/configprops
curl http://localhost:8084/changes
curl http://localhost:8084/health
# 停止
docker stop springboot3-demo
```
## C++ 客户端
```bash
docker build -f Dockerfile.cpp -t kenaito-conf-cpp-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-cpp-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-cpp-demo
```
## Rust 客户端
```bash
docker build -f Dockerfile.rust -t kenaito-conf-rust-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-rust-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-rust-demo
```
## Ruby 客户端
```bash
docker build -f Dockerfile.ruby -t kenaito-conf-ruby-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-ruby-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-ruby-demo
```
## Bash 客户端
```bash
docker build -f Dockerfile.bash -t kenaito-conf-bash-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-bash-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-bash-demo
```
## Dart 客户端
```bash
docker build -f Dockerfile.dart -t kenaito-conf-dart-demo .
# linux or mac
docker run -it --rm \
-e KENAITO_BASE_URL=http://host.docker.internal:8080 \
-e KENAITO_APP_NAME=kenaito-springboot-demo \
-e KENAITO_ENV=daily \
kenaito-conf-dart-demo
# windows
docker run -it --rm -e KENAITO_BASE_URL=http://host.docker.internal:8080 -e KENAITO_APP_NAME=kenaito-springboot-demo -e KENAITO_ENV=daily kenaito-conf-dart-demo
```
## 环境变量说明
| 变量名 | 说明 | 默认值 |
|-------------------------|----------|---------------------------|
| `KENAITO_BASE_URL` | 配置中心地址 | `http://localhost:8080` |
| `KENAITO_APP_NAME` | 应用名称 | `kenaito-springboot-demo` |
| `KENAITO_ENV` | 环境标识 | `daily` |
| `KENAITO_VERSION` | 配置版本 | `latest` |
| `KENAITO_TOKEN` | 应用 Token | 空 |
| `KENAITO_SYNC_INTERVAL` | 同步间隔(秒) | `10` |
| `KENAITO_CACHE_DIR` | 缓存目录 | `.` |
## 注意事项
1. **host.docker.internal**:容器内访问宿主机服务时使用 `host.docker.internal:8080`,Linux 系统可能需要添加
`--add-host host.docker.internal:host-gateway`
2. **网络模式**:如果配置中心也运行在 Docker 中,建议使用自定义网络:
```bash
docker network create kenaito-net
docker run --network kenaito-net --name kenaito-server ...
docker run --network kenaito-net -e KENAITO_BASE_URL=http://kenaito-server:8080 ...
```
3. **配置缓存**:各客户端会在运行目录生成 `config-cache.*` 缓存文件(Spring Boot 客户端为 `config-cache.log`),容器重启后可从缓存加载配置
4. **日志查看**:
- Go/.NET:直接输出到 stdout
- Node.js/Python/Spring Boot:使用各自日志框架
## 测试配置变更
1. 启动客户端容器
2. 在管理后台修改对应应用的配置
3. 等待同步间隔(默认 10 秒)
4. 观察客户端日志是否输出配置变更
5. 访问 HTTP 接口验证配置是否更新(Node.js/Python/Spring Boot)