You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TypeScript中Pulumi Stack Output导出失败问题排查

Pulumi导出Docker容器端口后pulumi stack output为空的解决办法

问题原因

Pulumi只会把入口文件(index.ts)中直接导出的变量识别为栈输出。你在my_container.ts里导出了custom_name_port,但index.ts仅导入了该文件,没有将这个变量重新导出,导致栈中没有任何输出项。

修复步骤

修改你的index.ts,把my_container.ts里的custom_name_port变量重新导出:

// index.ts
// 直接导出需要的变量
export { custom_name_port } from './containers/my_container';

import './utils/network';
import './utils/volumes';

或者也可以用另一种写法:

// index.ts
import { custom_name_port } from './containers/my_container';
// 显式导出
export { custom_name_port };

import './utils/network';
import './utils/volumes';

验证操作

  1. 重新执行部署命令:
pulumi up
  1. 查看栈输出:
pulumi stack output

此时就能看到custom_name_port的输出结果了。如果要直接把端口值传给Shell脚本,可直接执行:

PORT=$(pulumi stack output custom_name_port)
echo $PORT

额外说明

你的my_container通过pulumi.all().apply()创建,只要内部的Container资源ports配置正确(当前代码已设置external:7000),修复导出问题后就能正常获取到端口值。

内容的提问来源于stack exchange,提问作者Ryan Prentiss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 00:22:20