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

使用heroku.yml构建Docker镜像时端口绑定失败的解决方法

解决Heroku Docker部署R10启动超时问题

问题根源

你的Express应用绑定了localhost(127.0.0.1),该地址仅能在Docker容器内部访问,Heroku的路由系统无法连接到这个地址,导致进程无法在60秒内对外提供服务,触发R10 (Boot timeout)错误。

修复步骤

  1. 修改index.js的监听地址
    将代码中的HOST值改为0.0.0.0,或者直接省略HOST参数(Express默认会绑定0.0.0.0):
    const PORT = process.env.PORT || 3002;
    // 方案1:显式绑定0.0.0.0
    app.listen(PORT, "0.0.0.0", () => console.log(`listening on port ${PORT}`));
    // 方案2:省略HOST参数,使用默认值
    // app.listen(PORT, () => console.log(`listening on port ${PORT}`));
    
  2. 重新部署
    提交修改后的代码,重新推送到Heroku:
    git add index.js
    git commit -m "fix: bind to 0.0.0.0 for Heroku"
    git push heroku master
    

额外说明

  • Dockerfile中的EXPOSE 9000仅为容器暴露端口的声明,Heroku会动态分配实际运行端口(即process.env.PORT),无需修改该值。
  • heroku.yml的配置无问题,无需调整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 19:31:02