Having problems to build a docker production image due the sharp issues on ARM

Using the provided example in the documentation to build dockerized production images, the image will fail to start with the following error.

2024-04-29 19:28:50 yarn run v1.22.19
2024-04-29 19:28:50 $ strapi start
2024-04-29 19:28:51 [2024-04-29 17:28:51.522] debug: ⛔️ Server wasn't able to start properly.
2024-04-29 19:28:51 [2024-04-29 17:28:51.523] error: Could not load js config file /opt/node_modules/@strapi/plugin-upload/strapi-server.js: 
2024-04-29 19:28:51 Something went wrong installing the "sharp" module
2024-04-29 19:28:51 
2024-04-29 19:28:51 Cannot find module '../build/Release/sharp-linuxmusl-arm64v8.node'

here bellow my Dockerfile.prod


# Creating multi-stage build for production
FROM node:20-alpine as build
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1
ENV NODE_ENV=production

WORKDIR /opt/
COPY package.json yarn.lock ./
RUN yarn global add node-gyp
RUN yarn config set network-timeout 600000 -g && yarn install --production --ignore-scripts
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN yarn build

# Creating final production image
FROM node:20-alpine
RUN apk add --no-cache vips-dev
ENV NODE_ENV=production
WORKDIR /opt/
COPY --from=build /opt/node_modules ./node_modules
WORKDIR /opt/app
COPY --from=build /opt/app ./
ENV PATH /opt/node_modules/.bin:$PATH

RUN chown -R node:node /opt/app
USER node
EXPOSE 1337
CMD ["yarn", "start"]

This topic has been created from a Discord post (1234575544423551161) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

I’m currently facing the same issue

Did u manage to solve it?

here is what use right now ```# Creating multi-stage build for production
FROM node:20-alpine3.18 as build
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1
ENV NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
ENV SHARP_IGNORE_GLOBAL_LIBVIPS=1

WORKDIR /opt/
COPY package.json yarn.lock ./
RUN yarn global add node-gyp
RUN yarn config set network-timeout 600000 -g && yarn install
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN yarn build

Creating final production image

FROM node:20-alpine3.18
RUN apk add --no-cache vips-dev
ENV NODE_ENV=development
WORKDIR /opt/
COPY --from=build /opt/node_modules ./node_modules
WORKDIR /opt/app
COPY --from=build /opt/app ./
ENV PATH /opt/node_modules/.bin:$PATH

RUN chown -R node:node /opt/app
USER node
EXPOSE 1337
CMD [“yarn”, “start”]

but this is not the workaround

so you have to go under a Development env?

like I that I do not have the sharp issue

something weird is happening with mine, i can push mine and use it on app engine just ok

but when i run it on the docker on my machine it throws the error

rn i am trying to move to AWS and i really have to solve it

I think is something regardint to the used shapr version by strapi

I’ll try to reach them tomorrow if possible

do you use ARM arch on AWS?

oop that will be after tomorrow

i have yet to push in it

but for app engine it worked just fine

also it works fine when i run the project on local

i only get the problem when in docker

which is indeed something about the environment but idk what it could be

yes, is something to be debugged