将Node.jsDocker从本地(AppleM1)推送到Heroku时,继续遇到相同的部署错误(ExecFormatError)
发布图像时出现错误
2021-04-07T06:30:58.443089+00:00 heroku[web.1]: Starting process with command `node index.js`
2021-04-07T06:31:01.899268+00:00 app[web.1]: Error: Exec format error
我回到了只需要 Express 的最简单的 node.js 代码。无法理解它可能有什么问题。
设置如下:
- 在 Mac (Apple M1) 上运行 Docker 桌面
- 安装了最新的 Heroku、最新的 NPM、最新的 Node
- 使用 VS 代码
- dockerfile 设置:
WORKDIR /app
COPY package.json .
RUN npm install
COPY index.js .
CMD ["node", "index.js"]
- 包.json
{
"name": "SigningV2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo "Error: no test specified" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
- 配置文件
web: npm start
- 在线添加了两个变量
- PORT: 3000
- USE_NPM_INSTALL: TRUE (also tried without, same result)
ps:运行heroku本地网络时,它可以工作
回答
好的,找到了一个有效的解决方案。是 Apple M1 打破了这个标准设置(再次):(
我们需要强制 Heroku 兼容正确的平台。为此,我们将使用 Docker buildx。注意,不要使用 Heroku:container push 因为据我所知,它不支持不同平台的强制。
对我有用的是以下顺序:
# replace signingv2 with your own tag
docker buildx build --platform linux/amd64 -t signingv2 .
# make sure to use the name of your Heroku app
docker tag signingv2 registry.heroku.com/signingv2/web
# use docker push to push it to the Heroku registry
docker push registry.heroku.com/signingv2/web
# then use heroku release to activate
heroku container:release web -a signingv2
希望苹果 M1 的 Docker 很快在多个平台上得到支持。
THE END
二维码