15

I am pretty new to this Docker world and I am trying to deploy an image (nodejs-typescript service) from aws ECR to aws ECS but when I create the service inside the cluster this error appears and the taks never gets running:

exec /usr/local/bin/docker-entrypoint.sh: exec format error

My Dockerfile looks like this:

FROM node:lts-alpine

WORKDIR /usr/app

COPY package*.json ./
COPY tsconfig*.json ./

RUN yarn install --quiet

RUN yarn global add pm2

COPY . .

RUN yarn build

CMD ["pm2-runtime", "build/src/localServer.js"]

It is working fine on my pc when I build the image and run it:

(base) MacBook-Pro api % docker run -it -p 3000:3000 api-dev                                    
2022-12-06T15:35:27: PM2 log: Launching in no daemon mode
2022-12-06T15:35:27: PM2 log: App [localServer:0] starting in -fork mode-
2022-12-06T15:35:27: PM2 log: App [localServer:0] online
Connected to my_mongo_db_cluster
  Server ready at: http://localhost:3000/

The task definition is running on Linux/X86_64.

Any suggestions or tips to find out what is the problem? Thanks!

EDIT: when I add an ENTRYPOINT to my Dockerfile like this

# same steps

COPY . .

RUN yarn build

ENTRYPOINT ["pm2-runtime", "build/src/localServer.js"]

it throw this error exec /usr/local/bin/pm2-runtime: exec format error. The same happens when I change pm2-runtime to node

# same steps

COPY . .

RUN yarn build

ENTRYPOINT ["node", "build/src/localServer.js"]

Hope it helps.

1 Answers1

42

I found out what was the problem. It was my Apple M1 chip doing its incompatibility magic. For those who has the same problem, just adding the platform --platform=linux/amd64 in your Dockerfile seems to solve the problem:

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

# more instructions...
  • Same here, I had to build and push the image again and it worked – Jeferex Mar 10 '23 at 15:14
  • This fixed my problem as well! I had been troubleshooting this for a while too! – Heather92065 May 21 '23 at 14:41
  • 1
    Problems because I've omitted the platform spec when building images on the M1 have bitten me on so many occasions. Like you, this occurence was also found when I tried to run my container in Amazon EKS. Thanks for this. – miked Jun 30 '23 at 15:23
  • 1
    This needs a million +1s. I had been hitting this a bit for some other tech and kept trying to figure out what was really going on. I was starting to think that maybe I was getting deployed to Graviton instances by mistake. This answered EVERYTHING for me. – AfroRick Jul 30 '23 at 19:43
  • I've lost two days on research and then I've tried this and it worked! I owe you a beer! – DaX Aug 08 '23 at 20:36