I have created an image of my app using docker and when I run the docker image on my local machine it runs successfully, but the same image is erroring out when running using kubernetes.
The error is: exec /docker-entrypoint.sh: exec format error
Upon surfing the net for possible solutions I found the suggestion to add the shebang at the start of the docker-entrypoint.sh
. But this is a default .sh file as I've not specified any ENTRYPOINT in my dockerfile. I am not able to understand where to add the shebang.
Here is my dockerfile:
# pull the official base image
FROM node:18-alpine as builder
ENV NODE_ENV production
# set working direction
WORKDIR /app
# install application dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm i --production
# add app
COPY . .
# Build the app
RUN npm run build
# Bundle static assets with nginx
FROM nginx:1.23.1-alpine as production
ENV NODE_ENV production
# Copy built assets from builder
COPY --from=builder /app/build /usr/share/nginx/html
# Add your nginx.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Expose port
EXPOSE 80
# Start nginx
CMD ["nginx", "-g", "daemon off;"]
Some information about the image created:
"Architecture": "arm64",
"Variant": "v8",
"Os": "linux",
"Cmd": ["nginx", "-g", "daemon off;"],
"Entrypoint": ["/docker-entrypoint.sh"]
CodePudding user response:
Try something like in you Dockerfile
FROM --platform=linux/amd64 node:18-alpine as builder
Build the image and run it on K8s.
it could be due to the building image on Mac or Arm and your K8s cluster is not supporting that architecture.
CodePudding user response:
In addition to my comment, instead of guessing you can get the actual OS architecture supported by your Kubernetes node.
k describe node | grep "kubernetes.io/arch"
it should be something like this (avoid checking all node if many, describe just one)
Now build the docker image again
docker build --platform linux/x86-64 -t my_image_name .
or
services:
app:
platform: linux/amd64
image: nginx:1.23.1-alpine
now push the image and rollout deployment
docker push image_name