skip to Main Content

I am building a nodejs app with docker, I am building on an EC2 instance (ubuntu/arm64) ubuntu/images/hvm-ssd/ubuntu-focal-20.04-arm64-server-20211129 , and deploy it to AWS EKS, the node I am using is ubuntu-eks/k8s_1.22/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20220630, however the pod goes into CrashLoopBackOff status, and gives me the following error:

exec /usr/local/bin/yarn: exec format error

here is how my Dockerfile looks like

FROM --platform=linux/arm64 node:16-alpine as builder

RUN apk --no-cache add --virtual builds-deps build-base python3

RUN mkdir /app
WORKDIR /app

COPY ./package.json ./yarn.lock ./
RUN yarn install --production

FROM --platform=linux/arm64 node:16-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
USER node
COPY --chown=node:node ./ .
COPY --from=builder /app/node_modules ./node_modules

EXPOSE 4004

ENTRYPOINT ["yarn", "run", "start"]

Could someone help me with this ?

2

Answers


  1. Chosen as BEST ANSWER

    The reason turned out to be the image was built one linux/arm64, but was running on linux/amd64, after I changed my node to be linux/arm64, it starts to run.


  2. As from docker API version 1.40, you can specify the platform upon which your image needs to be built by using the --platform option.

    docker build . --platform=linux/amd64
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search