strapi-community / strapi-tool-dockerize

Easy add support for docker to your strapi project
MIT License
504 stars 34 forks source link

docker build : /bin/sh: node-gyp: not found #97

Closed sven0219 closed 8 months ago

sven0219 commented 9 months ago

🐛 Bug Report

🤷‍♀️ What did you do

This is my Dockerfile

FROM node:18-alpine
# Installing libvips-dev for sharp Compatibility
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}

WORKDIR /opt/
COPY package.json yarn.lock ./
RUN yarn config set network-timeout 600000 -g && yarn install

WORKDIR /opt/app
COPY . .
ENV PATH /opt/node_modules/.bin:$PATH
RUN chown -R node:node /opt/app
USER node
RUN ["yarn", "build"]
EXPOSE 1337
CMD ["yarn", "develop"]

package.json

{
  "name": "cybex-cms",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {
    "develop": "strapi develop",
    "start": "strapi start",
    "build": "strapi build",
    "strapi": "strapi"
  },
  "devDependencies": {},
  "dependencies": {
    "@strapi/plugin-i18n": "4.14.3",
    "@strapi/plugin-users-permissions": "4.14.3",
    "@strapi/strapi": "4.14.3",
    "better-sqlite3": "8.6.0",
    "pg": "^8.11.3"
  },
  "author": {
    "name": "A Strapi developer"
  },
  "strapi": {
    "uuid": "a82288e0-8613-4f49-80b0-37d9f5fede2b"
  },
  "engines": {
    "node": ">=16.0.0 <=20.x.x",
    "npm": ">=6.0.0"
  },
  "license": "MIT"
}

⛔️ Error log

when build this docker image, I got this error

[5/5] Building fresh packages...
error /opt/node_modules/sharp: Command failed.
Exit code: 127
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
Arguments: 
Directory: /opt/node_modules/sharp
Output:
sharp: Detected globally-installed libvips v8.14.3
sharp: Building from source via node-gyp
/bin/sh: node-gyp: not found
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error: building at STEP "RUN yarn config set network-timeout 600000 -g && yarn install": while running runtime: exit status 127```

### 🕵️‍♀️ Stack trace

```bash
Stack Trace

## 🙇‍♀️ Expected behavior/code

A clear and concise description of what you expected to happen (or code).

## 👩‍💻 Environment

- 📦 Node version: 18
- 💻 OS:  MacOS 13.6

## 💡 Possible Solution

<!-- Only if you have suggestions on a fix for the bug -->

## 📺 Additional context/Screenshots

<!-- Add any other context about the problem here. If applicable, add screenshots to help explain. -->
Eventyret commented 9 months ago

If this is on Mac make sure you have libvips installed

kenornotes commented 8 months ago

I solved this by changing the docker image from node:18-alpine to node:18.17.1-alpine https://forum.strapi.io/t/docker-strapi-node-18-16-alpine-sharp-node-gyp-problem-solved/32245

sven0219 commented 8 months ago

If this is on Mac make sure you have libvips installed

It is working for me