带有 Docker 的 Heroku - 错误 H14:没有 Web 进程正在运行 [英] Heroku with Docker - ERROR H14:No web processes running
问题描述
我正在尝试通过 Heroku 上的 Docker 容器在 express 和 Pm2 中部署一个简单的 nodejs 应用程序.
I'm trying to deploy a simple nodejs app served in express and Pm2, via a Docker container on Heroku.
按照heroku定义的步骤,容器成功推送到heroku:
Following the steps defined by heroku, the container is sucessfully pushed to heroku:
- heroku 容器:登录
- heroku 容器:push name-of-container -a name-of-herokuApp
- heroku container:release name-of-container -a name-of-herokuApp
- heroku ps:scale name-of-container=1 -a name-of-herokuApp
这是 heroku 的日志,显示运行图像和为进程分配一个 dyno 的成功容器部署日志
Here is the log of heroku showing the success on running the image and assigning a dyno to the process Container Deployment Log
这里是问题出现的时候:在访问应用程序路由时抛出 Heroku H14 错误,当进程没有 Dynos 时会发生这种情况,在我的情况下它有.错误 H14 日志
Here is when the problem comes: while accessing to the apps routes the Heroku H14 Error is throw, which happens when a proccess doesn't have Dynos, which in my case it have. Error H14 Log
我没有想法,因为这个错误引发的原因.我知道这可能是一个愚蠢的错误 XD!
I'm out of ideas as the reason this error is raising. I know it might be a silly mistake thought XD!!
这是我的应用程序的代码:
Here you got the code for my app:
const express = require('express')
const app = express()
//require('./database')
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
console.log('App is Running, yaaaay')
app.get("/", (req,res) => {
res.send("OK")
})
app.listen(3000)
及其与 Pm2 一起运行:
and its run with Pm2:
"scripts": {
"dev": "nodemon ./src/app",
"start": "pm2-runtime ./src/app.js --watch --name WD-Bot"
},
另外,这里有我的 DockerFile.我是 Docker 的新手,所以我可能在这里搞砸了 T-T?
Also, here you got my DockerFile. I'm pretty newbie on Docker, so i probably messed up on here T-T?
FROM node:12.18-alpine
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
推荐答案
你做到了:
heroku container:push name-of-container -a name-of-herokuApp
您假设这是容器的名称.那是错误的.根据 https://devcenter.heroku.com/articles/container-registry-and-runtime#build-an-image-and-push 这是进程类型:
You assume that's the name of the container. That's wrong. As per https://devcenter.heroku.com/articles/container-registry-and-runtime#build-an-image-and-push that's the process type:
heroku 容器:push
您收到的错误信息是:
ERROR H14:No web processes running
您将进程命名为 wd-bot
而不是 web
.
You named your process wd-bot
and not web
.
将您的进程类型更改为 web
后,您还必须正确绑定 $PORT
.请参阅:https://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error
但这是一个不同的话题,是一个新问题.
After changing your process type to web
you'll have to properly bind the $PORT
as well. See: https://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error
But that's a different topic and is a new question.
这篇关于带有 Docker 的 Heroku - 错误 H14:没有 Web 进程正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!