Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an error on dockerising nest.js application

Tags:

docker

nestjs

I am working on a Nest.js application and this is the Dockerfile that we have. When I run this I am getting an error on the npm run build step in docker. This is the build task in package.json. "build": "nest build"

sh: nest: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! [email protected] build: `nest build`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Dockerfile

# Build
FROM node:8-alpine as builder

COPY package.json /usr/src/atom/package.json
COPY package-lock.json /usr/src/atom/package-lock.json
WORKDIR /usr/src/atom

# Install dependencies
RUN npm install --production --loglevel warn

ARG APPLICATION
ARG BRANCH
ARG BUILD_NUMBER
ARG SHA
ENV NODE_ENV qa
ENV VERSION 1.0.0


## Copy app directory in container and set workdir
COPY . /usr/src/atom

# Build & Test Coverage
RUN set -x \
  && npm run build \
  && echo "{ \"status\": \"Ok\", \"result\": { \"version\": \"$VERSION\", \"branchName\": \"$BRANCH\", \"SHA\": \"$SHA\", \"buildDate\": \"$(date)\", \"buildNumber\": \"$BUILD_NUMBER\", \"environment\": \"$NODE_ENV\" } }" > build.json

# Release
FROM node:8-alpine 

ENV PORT 3000

COPY --from=builder /usr/src/atom/node_modules /usr/src/atom/node_modules
COPY --from=builder /usr/src/atom/dist /usr/src/atom/dist
COPY --from=builder /usr/src/atom/package.json /usr/src/atom/package.json
COPY --from=builder /usr/src/atom/build.json /usr/src/atom/build.json
WORKDIR /usr/src/atom

EXPOSE $PORT
## Run supervisor as foreground process
CMD bash -c "npm run start:prod && /usr/bin/supervisord" 

like image 641
Vinz and Tonz Avatar asked Mar 05 '20 22:03

Vinz and Tonz


1 Answers

@nestjs/cli (where the nest command comes from) is by default in devDependencies. Unless you've modified your deps in package.json, running npm i --production will not install @nestjs/cli which will lead to the error you currently have. You can either use a multi-staged dockerfile or move @nestjs/cli to your dependencies instead of devDeps.

like image 177
Jay McDoniel Avatar answered Oct 18 '22 06:10

Jay McDoniel