Skip to content

Docker 部署

构建上下文 必须是仓库根目录(需要 go.mod / pkg / internal),故 -f 指向 Dockerfile、. 作上下文。

单体部署

bash
docker build -f cmd/standalone/Dockerfile -t ruoyi-go:standalone .
docker run -d -p 8080:8080 ruoyi-go:standalone

镜像内已打进 configs。改配置有两种方式:挂载覆盖整个目录 -v ./configs:/app/configs:ro,或只覆盖某个文件。 环境变量改不了配置——pkg/config 没开 viper.AutomaticEnv

健康检查内置 GET /system/ping

多模块部署

每个模块一个镜像,由 MODULE 构建参数选 cmd/modular 下的入口:

bash
docker build -f cmd/modular/Dockerfile --build-arg MODULE=auth     -t ruoyi-go:auth .
docker build -f cmd/modular/Dockerfile --build-arg MODULE=system   -t ruoyi-go:system .
docker build -f cmd/modular/Dockerfile --build-arg MODULE=monitor  -t ruoyi-go:monitor .
docker build -f cmd/modular/Dockerfile --build-arg MODULE=resource -t ruoyi-go:resource .

四个容器各自监听 :8080,靠容器网络命名空间隔离,对外端口由 docker run -p 或上游 nginx upstream 区分。健康检查内置 GET /ping(四模块路由均空前缀注册,探针路径一致)。

workerId

同模块多副本必须互异 同模块起多副本时,workerId 必须互异——副本挂载各自的 yaml 覆盖:

bash
-v ./configs/system-2.yaml:/app/configs/system.yaml:ro

镜像基础信息

  • 基础镜像 alpine:3.20,已装 ca-certificates(对象存储 / 阿里云短信 / 三方登录均 HTTPS 出站)与 tzdata(DSN 用了 loc=Local,缺 tzdata 会按 UTC 写库,时间字段差 8 小时)。
  • CGO_ENABLED=0 静态链接,-trimpath -ldflags="-s -w" 去绝对路径与符号表。
  • 以非 root 用户 ruoyi(uid 10001)运行。

基于 MIT 协议开源