strapi-docker: npm run build fails when using in a docker container

Strapi version: 3.0.0-beta.6 Node: 12

Locally works ok, but inside a docker container, it cannot build an admin panel.

Dockerfile contents:

FROM node:11.5.0-alpine

COPY . /var/www/cms

WORKDIR /var/www/cms

RUN apk add --no-cache \
  autoconf \
  automake \
  gcc \
  libc-dev \
  libtool \
  make \
  nasm \
  zlib-dev \
  && chmod +x ./strapi.sh

RUN npm install

EXPOSE 1337

CMD ["./strapi.sh"]

strapi.sh contents:

#!/bin/sh
set -ea

_stopStrapi() {
  echo "Stopping strapi"
  kill -SIGINT "$strapiPID"
  wait "$strapiPID"
}

trap _stopStrapi SIGTERM SIGINT

cd /var/www/cms

APP_NAME=${APP_NAME}
DATABASE_HOST=${DATABASE_HOST}
DATABASE_PORT=${DATABASE_PORT}
DATABASE_NAME=${DATABASE_NAME}
DATABASE_USERNAME=${DATABASE_USERNAME}
DATABASE_PASSWORD=${DATABASE_PASSWORD}

NODE_ENV=production npm run build
NODE_ENV=production npm run start &

strapiPID=$!
wait "$strapiPID"

On the step - NODE_ENV=production npm run build - it’s failing with following errors:

cms    | Building your admin UI with production configuration ...
cms    | ℹ Compiling Webpack
cms    | (node:17) UnhandledPromiseRejectionWarning: Error: spawn Unknown system error -8
cms    |     at ChildProcess.spawn (internal/child_process.js:372:11)
cms    |     at Object.spawn (child_process.js:543:9)
cms    |     at module.exports (/var/www/cms/node_modules/imagemin-pngquant/node_modules/execa/index.js:204:26)
cms    |     at input (/var/www/cms/node_modules/imagemin-pngquant/index.js:52:13)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 39 (5 by maintainers)

Most upvoted comments

I just had this issue running strapi/strapi:latest with docker-compose, following this guideline, but using mysql instead of Mongo DB: https://strapi.io/blog/how-to-run-a-strapi-dev-stack-with-docker-compose

Error loading the local develop command. Strapi might not be installed in your “node_modules”. You may need to run “npm install”

The container won’t stay up, so I cannot bash into it and run npm install manually.

HI,

We just released a full rebuild of our docker image 🎉 We are closing the issues and open PRs to start fresh.

If you feel like something is missing or want to add things feel free to open new PRs ! 💯

@alexandrebodin I just got a build that failed for the first time with issue

edit Nevermind, I think it was a matter of me trying to use /srv/app for my custom image but it looks like it conflicts with the Base image.

[3/5] Fetching packages...
warning url-loader@1.1.2: Invalid bin field for "url-loader".
info fsevents@2.1.3: The platform "linux" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.13: The platform "linux" is incompatible with this module.
info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation.
[4/5] Linking dependencies...
warning "strapi-admin > bootstrap@4.5.0" has unmet peer dependency "jquery@1.9.1 - 3".
warning "strapi-admin > bootstrap@4.5.0" has unmet peer dependency "popper.js@^1.16.0".
warning "strapi-plugin-graphql > graphql-playground-middleware-koa@1.6.13" has unmet peer dependency "koa@^2".
warning "strapi-plugin-graphql > graphql-type-long@0.1.1" has incorrect peer dependency "graphql@^0.9.1 || ^0.10.0 || ^0.12.0 || ^0.13.0".
warning "strapi-plugin-users-permissions > grant-koa@5.1.1" has unmet peer dependency "koa@>=2.0.0".
[5/5] Building fresh packages...
Done in 49.77s.
Removing intermediate container c09f4541deb0
 ---> 93bbb505f85f
Step 7/10 : COPY . .
 ---> 94d02a7cbc97
Step 8/10 : RUN yarn build --clean
 ---> Running in 106569bbbdd1
yarn run v1.22.4
$ strapi build --clean
Error loading the local build command. Strapi might not be installed in your "node_modules". You may need to run "npm install"
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command '/bin/sh -c yarn build --clean' returned a non-zero code: 1
##[error]Process completed with exit code 1.
FROM strapi/strapi:3.1.1-node12

WORKDIR /srv/app

COPY ./package.json ./
COPY ./yarn.lock ./

ENV NODE_ENV staging

RUN yarn install --prod

COPY . .

RUN yarn build --clean

EXPOSE 1337

CMD ["yarn", "start"]

Just found: https://github.com/strapi/strapi/issues/3383, it’s related to ram i guess. Node-sass eats too much ram. I just got the same npm ERR! Exit status 137, sometimes it builds, sometimes - not. Going to try to increase RAM. Node version doesn’t matter actually.

I just released a new version of the image that fixing an error with the node_modules not being installed if the project doesn’t have a package-lock or yarn.lock file. can you test this @rogoit ?

It worked for me. thanks 😉

I just released a new version of the image that fixing an error with the node_modules not being installed if the project doesn’t have a package-lock or yarn.lock file. can you test this @rogoit ?

@alexandrebodin I am sorry to say this but it is a lame strategy to close an unsolved issue just because there’s a rebuild of the images. It seems like people are still having the same issues that was first reported a year back. So, it is evident that “rebuilding” images didn’t fix anything.

image

It’s kinda working, i’ll try to remove container and build up again, to exclude randomness.