2

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"]
SHRUTHI BHARADWAJ
  • 587
  • 2
  • 5
  • 15
  • 1
    seems the cluster does not support `arm64` Architecture image, `docker build --platform linux/x86-64 -t my_image_name .` , push the image and it should work – Adiii Aug 11 '22 at 12:58
  • run `docker buildx imagetools inspect your_image` and it will show on which `Architecture` it will work – Adiii Aug 11 '22 at 13:00
  • @Adiii Thanks. I am using docker-compose how to add the platform specification? – SHRUTHI BHARADWAJ Aug 11 '22 at 13:30
  • @Adiii `docker buildx imagetools inspect your_image` Didn't get much information it just gave the Name, MediaType, and Digest – SHRUTHI BHARADWAJ Aug 11 '22 at 13:31
  • https://stackoverflow.com/questions/65456814/docker-apple-silicon-m1-preview-mysql-no-matching-manifest-for-linux-arm64-v8 – Adiii Aug 11 '22 at 13:38

2 Answers2

2

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.

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
1

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)

enter image description here

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
Adiii
  • 54,482
  • 7
  • 145
  • 148