
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
https://img.shields.io/docker/pulls/softinstigate/restheart.svg?maxAge=2592000](https://hub.docker.com/r/softinstigate/restheart/) https://img.shields.io/github/stars/SoftInstigate/restheart?label=GitHub%20Stars](https://github.com/SoftInstigate/restheart)
开源 Java 服务器,无需编写代码即可从 MongoDB 集合自动生成 REST、GraphQL 和 WebSocket API。
完美适配容器化环境 — 无状态架构专为 Docker、Kubernetes、AWS ECS、App Runner 及任何容器编排平台设计。
✅ 无状态设计 — 无本地状态,轻松实现水平扩展
✅ 快速启动 — 秒级就绪,适合自动扩缩容场景
✅ 轻量级 — 资源占用高效(原生镜像约 80MB)
✅ Java 25 虚拟线程 — 高效处理 10K+ 并发连接
✅ 优化 JVM — G1GC 调优,适用于堆内存 ≤2GB 的高吞吐量 REST API
✅ 基于环境的配置 — 通过 RHO 环境变量进行配置
✅ 健康检查端点 — 内置 /ping 和 /metrics 供编排平台使用
✅ 12-Factor 应用 — 遵循云原生最佳实践
bashcurl https://raw.githubusercontent.com/SoftInstigate/restheart/master/docker-compose.yml \ --output docker-compose.yml && docker compose up
通过 http://localhost:8080 访问 RESTHeart
bashdocker run -d \ --name restheart \ -p 8080:8080 \ -e RHO="/mclient/connection-string->'mongodb://mongodb:27017'" \ docker.xuanyuan.run/softinstigate/restheart:latest
bash# 启动 MongoDB docker run -d --name mongodb -p 27017:27017 docker.xuanyuan.run/mongo:7 # 启动 RESTHeart docker run -d \ --name restheart \ --link mongodb \ -p 8080:8080 \ -e RHO="/mclient/connection-string->'mongodb://mongodb:27017'" \ docker.xuanyuan.run/softinstigate/restheart:latest
测试 API:
bashcurl http://localhost:8080/ping
免责声明:以下示例仅供参考,您需要根据具体需求、安全策略和基础设施设置进行调整。
部署示例:
yamlapiVersion: apps/v1 kind: Deployment metadata: name: restheart spec: replicas: 3 selector: matchLabels: app: restheart template: metadata: labels: app: restheart spec: containers: - name: restheart image: docker.xuanyuan.run/softinstigate/restheart:latest # 使用 :native 以实现更快的自动扩缩容 ports: - containerPort: 8080 env: - name: RHO value: "/mclient/connection-string->'mongodb://mongodb-service:27017'" livenessProbe: httpGet: path: /ping port: 8080 initialDelaySeconds: 30 periodSeconds: 10 readinessProbe: httpGet: path: /ping port: 8080 initialDelaySeconds: 5 periodSeconds: 5 resources: requests: memory: "256Mi" cpu: "250m" limits: memory: "512Mi" cpu: "500m" --- apiVersion: v1 kind: Service metadata: name: restheart-service spec: selector: app: restheart ports: - port: 80 targetPort: 8080 type: LoadBalancer
K8s 核心特性:
任务定义:
json{ "family": "restheart", "networkMode": "awsvpc", "requiresCompatibilities": ["FARGATE"], "cpu": "256", "memory": "512", "containerDefinitions": [ { "name": "restheart", "image": "softinstigate/restheart:latest", "portMappings": [ { "containerPort": 8080, "protocol": "tcp" } ], "environment": [ { "name": "RHO", "value": "/mclient/connection-string->'mongodb+srv://user:pass@cluster.mongodb.net'" } ], "healthCheck": { "command": ["CMD-SHELL", "curl -f http://localhost:8080/ping || exit 1"], "interval": 30, "timeout": 5, "retries": 3 }, "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-group": "/ecs/restheart", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" } } } ] }
ECS 优势:
最简单的 AWS 部署:
bashaws apprunner create-service \ --service-name restheart-api \ --source-configuration '{ "ImageRepository": { "ImageIdentifier": "softinstigate/restheart:latest", "ImageRepositoryType": "ECR_PUBLIC", "ImageConfiguration": { "Port": "8080", "RuntimeEnvironmentVariables": { "RHO": "/mclient/connection-string->\"mongodb+srv://user:pass@cluster.mongodb.net\"" } } }, "AutoDeploymentsEnabled": false }' \ --instance-configuration '{ "Cpu": "1 vCPU", "Memory": "2 GB" }'
App Runner 优势:
bashdocker service create \ --name restheart \ --replicas 3 \ --publish 8080:8080 \ --env RHO="/mclient/connection-string->'mongodb://mongodb:27017'" \ --health-cmd "curl -f http://localhost:8080/ping || exit 1" \ --health-interval 30s \ --health-retries 3 \ softinstigate/restheart:latest
RHO 环境变量用于覆盖 YAML 配置:
bashdocker run -e RHO="/http-listener/host->'0.0.0.0';/http-listener/port->8080" \ docker.xuanyuan.run/softinstigate/restheart:latest
bashdocker run -v ./restheart.yml:/opt/restheart/etc/restheart.yml \ docker.xuanyuan.run/softinstigate/restheart:latest
示例 restheart.yml:
yamlmongo-uri: mongodb://mongodb:27017 http-listener: host: 0.0.0.0 port: 8080 auth: mechanism: jwtAuthentication jwt: key: your-secret-key cors: enabled: true allow-origin: "*"
Kubernetes Secrets:
yamlapiVersion: v1 kind: Secret metadata: name: restheart-secrets type: Opaque stringData: mongo-uri: "mongodb+srv://user:password@cluster.mongodb.net" jwt-key: "your-jwt-secret-key" --- env: - name: MONGO_URI valueFrom: secretKeyRef: name: restheart-secrets key: mongo-uri - name: RHO value: "/mclient/connection-string->env('MONGO_URI')"
AWS Secrets Manager (ECS):
json{ "secrets": [ { "name": "MONGO_URI", "valueFrom": "arn:aws:secretsmanager:region:account:secret:mongo-uri" } ] }
latest — 最新稳定版(Eclipse Temurin JRE 25,推荐生产环境使用)distroless — 最小化安全加固镜像(Chainguard distroless JRE)graalvm — GraalVM JDK,支持多语言插件(JavaScript、Python、TypeScript)native — GraalVM 原生编译二进制文件(启动最快,体积最小)X.Y.Z — 特定版本标签(如 8.1.0、8.2.0)X.Y.Z-distroless、X.Y.Z-graalvm、X.Y.Z-native — 特定版本的变体| 镜像 | 基础 | 大小 | 启动时间 | JVM | 适用场景 |
|---|---|---|---|---|---|
latest | Eclipse Temurin JRE 25 | ~200MB | ~3s | ✅ 完整 JVM | 通用目的,生产环境 |
distroless | Chainguard distroless | ~150MB | ~3s | ✅ 完整 JVM | 安全关键环境,最小***面 |
graalvm | GraalVM CE 25 | ~300MB | ~3s | ✅ GraalVM | 多语言插件(JS、TS、Python) |
native | Debian slim + 原生二进制 | ~80MB | <1s | ❌ AOT 编译 | 无服务器,边缘计算,快速扩缩容 |
latest — 适用于大多数生产部署
distroless — 适用于安全关键环境
graalvm — 当需要多语言插件时使用
native — 适用于资源受限或无服务器部署
标准部署:
bashdocker run -p 8080:8080 \ -e RHO="/mclient/connection-string->'mongodb://mongodb:27017'" \ docker.xuanyuan.run/softinstigate/restheart:latest
安全加固部署:
bashdocker run -p 8080:8080 \ -e RHO="/mclient/connection-string->'mongodb://mongodb:27017'" \ docker.xuanyuan.run/softinstigate/restheart:distroless
带 JavaScript 插件:
bashdocker run -p 8080:8080 \ -v ./plugins:/opt/restheart/plugins \ -e RHO="/mclient/connection-string->'mongodb://mongodb:27017'" \ docker.xuanyuan.run/softinstigate/restheart:graalvm
无服务器/边缘部署:
bashdocker run -p 8080:8080 \ -e RHO="/mclient/connection-string->'mongodb://mongodb:27017'" \ docker.xuanyuan.run/softinstigate/restheart:native
native 镜像特别适合:
latest/ping、/metrics)🚀 MongoDB API 网关 — 无需编写后端代码,即时获得 REST/GraphQL API
📱 移动/Web 后端 — 自动生成端点,加速开发
⚡ 微服务 — 轻量级、无状态服务,适合容器编排
🔄 实时应用 — WebSocket 支持,实现实时更新和通知
🏢 MongoDB Data API 替代方案 — 自托管替代已弃用的 Atlas Data API
🌐 多区域部署 — 无状态设计,完美支持全球负载均衡
🧪 原型设计与 MVP — 几分钟内搭建功能完备的后端
graalvm 镜像)无需编写代码即可实现标准数据库操作。仅在需要自定义业务逻辑时编写插件。
注意: JavaScript、TypeScript 和 Python 插件需要 graalvm 镜像变体。Java 插件适用于所有镜像变体。
bash# 创建文档 curl -X POST http://localhost:8080/db/collection \ -H "Content-Type: application/json" \ -d '{"name": "Alice", "age": 30}' # 使用过滤器查询 curl "http://localhost:8080/db/collection?filter={\"age\":{\"\$gt\":25}}" # 聚合管道 curl -X POST http://localhost:8080/db/collection/_aggrs/pipeline \ -H "Content-Type: application/json" \ -d '[{"$group": {"_id": "$status", "count": {"$sum": 1}}}]'
graphqlquery { collection(filter: "{'age': {'$gt': 25}}", limit:
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务