Keep running into the same deployment error (Exec Format Error) when pushing Node.js Docker from local (Apple M1) to Heroku
Asked Answered
M

4

21

Error I get when releasing image

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

I went back to the most simple node.js code that only requires Express. Can not get my head around it what could be wrong.

Setup is as following:

  • running Docker Desktop on Mac (Apple M1)
  • installed latest Heroku, latest NPM, latest Node
  • working with VS Code
  • dockerfile setup:
WORKDIR /app
COPY package.json .
RUN npm install
COPY index.js .
CMD ["node", "index.js"]
  • package.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"
  }
}
  • Procfile
web: npm start
  • added two variables online
- PORT: 3000
- USE_NPM_INSTALL: TRUE  (also tried without, same result)

ps: when running heroku local web, it works

Meridel answered 7/4, 2021 at 8:57 Comment(0)
M
52

Ok, found a working solution. It's Apple M1 that is breaking this standard setup (again) :(

We need to force the correct platform to be compatible by Heroku. To do this, we are going to use Docker buildx. Note, do not use Heroku:container push because as far as I know, that does not support the forcing of different platforms.

What worked for me is the following sequence:

# 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

Hope that Docker for Apple M1 is supported on several platforms soon.

Meridel answered 8/4, 2021 at 9:46 Comment(2)
It is Nov 2021 and this appears to have solved the very mysterious Heroku H10 error I kept getting: "Error: Exec format error". I'm on an M1 2020 MBP. Why Heroku's cli container:build doesn't account for a change in architecture, not sure.Arvind
This was so helpful! Thank you so much for taking the time. Running on M1 and having had no clue about the nitty-gritty details of architectural differences, I had no clue why my images/containers worked on my machine while they failed on GCP, Heroku, Digital Ocean, etc. Also didn't know about buildx before. Thanks a lot!Nasopharynx
E
12

In my case I solved the issue by changing the Dockerfile.

I updated it to pull node image for linux/amd64:

FROM --platform=linux/amd64 node:14.17.0-alpine

Rebuild, push to heroku and it should work fine then.

Etana answered 20/2, 2022 at 0:56 Comment(0)
A
1

I modified @Jinxvar 's solution slightly as I had to use the --load option to be able to push the image. Otherwise, it didn't even show up when I ran docker image ls

Here's what worked for me:

$ docker buildx build --load --platform linux/amd64 -t registry.heroku.com/app_name/web .

$ docker push registry.heroku.com/app_name/web:latest
Ajmer answered 22/1, 2022 at 17:33 Comment(0)
G
0

Jinxvar solution works. I had a different issue after

"message": "no pg_hba.conf entry for host "xxx", user "xxx", database "xxx", SSL off"

If your using Postgres for the DB and get the exit error make sure to include this in your pg config.

"ssl": true,
"extra": {
  "ssl": { "rejectUnauthorized": false }
},

This route is probably not safe to run in production though. When it is ready for production change the config above to

"SSL": {
"ca": process.env.<your-SSL-cert-var>,

}

Garnet answered 25/5, 2021 at 15:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.