
thekevjames/gcloud-pubsub-emulatorgcloud-pubsub-emulator 是一个基于 marcelcorso/gcloud-pubsub-emulator 构建的Docker镜像,提供Google Cloud Pub/Sub服务的本地模拟器。该镜像支持自动构建以追踪 gcloud 工具的最新版本,并集成了更新后的 pubsubc 工具,可在启动时自动初始化主题(topics)和订阅(subscriptions)。主要用于本地开发、集成测试及CI/CD流程中,模拟Pub/Sub服务环境,避免依赖真实云资源。
gcloud 新版本自动构建,支持按版本号(\d+.\d+.\d+)、提交哈希(commit hash)及 latest 标签区分镜像版本。console$ docker run --rm -it -p 8681:8681 thekevjames/gcloud-pubsub-emulator:latest
console$ docker run --rm -it -p 8681:8681 quay.io/thekevjames/gcloud-pubsub-emulator:latest
启动后,通过环境变量 PUBSUB_EMULATOR_HOST 指向模拟器地址:
console$ export PUBSUB_EMULATOR_HOST=localhost:8681 $ ./your_application # 应用程序将使用模拟器而非真实Pub/Sub服务
支持通过配置文件或环境变量两种方式,在启动时自动创建主题和订阅。
配置文件路径
默认路径为 /etc/pubsubc/config.json,可通过环境变量 PUBSUBC_CONFIG 自定义路径。
配置文件格式
JSON数组格式,每个元素为项目-主题配置,支持嵌套订阅定义。示例:
json[ { "topic": "topic1", // 主题名称(必填) "project": "project1" // 项目ID(必填) }, { "topic": "topic2", "project": "project1", "subscriptions": [ // 可选,订阅列表 { "name": "subscription1", // 订阅名称(必填) "push_config": { // 可选,推送订阅配置(无此键则为拉取订阅) "push_endpoint": "http://localhost:3001/messages" // 推送目标地址 } }, { "name": "subscription2" // 拉取订阅 } ] } ]
启动命令示例
挂载自定义配置文件并指定路径:
console$ docker run --rm -it \ -p 8681:8681 \ -e PUBSUBC_CONFIG=/custom/config.json \ # 自定义配置文件路径 -v ./local-config.json:/custom/config.json \ # 挂载本地配置文件 thekevjames/gcloud-pubsub-emulator:latest
仅在未指定配置文件时生效,通过 PUBSUB_PROJECT<N>(N 从1开始)定义项目及主题/订阅。
环境变量格式
格式:PROJECTID,TOPIC1,TOPIC2:SUBSCRIPTION1:SUBSCRIPTION2,TOPIC3:SUBSCRIPTION3
TOPIC_ID[:SUBSCRIPTION1[:SUBSCRIPTION2]...](: 后为订阅名称,可多个)。示例
项目 company-dev 包含:
invoices,订阅 invoice-calculator;chats,订阅 slack-out、irc-out;notifications,无订阅。环境变量配置:
console$ export PUBSUB_PROJECT1=company-dev,invoices:invoice-calculator,chats:slack-out:irc-out,notifications
启动命令示例
console$ docker run --rm -it \ -p 8681:8681 \ -e PUBSUB_PROJECT1=company-dev,invoices:invoice-calculator,chats:slack-out:irc-out,notifications \ thekevjames/gcloud-pubsub-emulator:latest
多项目配置
通过 PUBSUB_PROJECT2、PUBSUB_PROJECT3 等添加更多项目,格式同上。
当启用自动创建主题/订阅时,需暴露端口 8682 用于健康检查(模拟器就绪后监听此端口)。检查方法示例:
nc:nc -z 127.0.0.1 8682bash:true &>/dev/null </dev/tcp/127.0.0.1/8682wget:wget 127.0.0.1:8682若模拟器启动缓慢导致主题/订阅创建超时(默认15秒),可通过 PUBSUB_EMULATOR_WAIT_TIMEOUT 环境变量调整超时时间(单位:秒)。示例:
console$ docker run --rm -it \ -p 8681:8681 \ -e PUBSUB_EMULATOR_WAIT_TIMEOUT=60 \ # 超时设为60秒 -e PUBSUB_PROJECT1=company-dev,invoices:invoice-calculator \ thekevjames/gcloud-pubsub-emulator:latest
console$ docker run --rm -it \ -p 8681:8681 \ # 模拟器服务端口 thekevjames/gcloud-pubsub-emulator:latest
console$ docker run --rm -it \ -p 8681:8681 \ -p 8682:8682 \ # 健康检查端口 -e PUBSUBC_CONFIG=/config/pubsub.json \ -v ./my-pubsub-config.json:/config/pubsub.json \ # 挂载本地配置文件 thekevjames/gcloud-pubsub-emulator:latest
yamlversion: '3' services: pubsub-emulator: image: thekevjames/gcloud-pubsub-emulator:latest ports: - "8681:8681" # 模拟器服务端口 - "8682:8682" # 健康检查端口 environment: - PUBSUB_EMULATOR_WAIT_TIMEOUT=60 # 超时配置 - PUBSUBC_CONFIG=/config/config.json # 配置文件路径 volumes: - ./local-config.json:/config/config.json # 挂载配置文件 restart: unless-stopped
| 环境变量 | 作用描述 | 默认值 | 示例 |
|---|---|---|---|
PUBSUBC_CONFIG | 自动初始化配置文件路径(仅配置文件方式生效) | /etc/pubsubc/config.json | /custom/pubsub-config.json |
PUBSUB_PROJECT<N> | 项目及主题/订阅配置(仅环境变量方式生效,N从1开始) | 无 | company-dev,invoices:calc,chats:slack:irc,notifications(项目1) |
PUBSUB_EMULATOR_WAIT_TIMEOUT | 模拟器就绪超时时间(秒) | 15 | 60 |
latest:主分支最新构建版本。\d+.\d+.\d+:对应 gcloud 工具版本的构建(如 460.0.0)。a1b2c3d4),用于版本精确追溯。





manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务