teachMe
teachMe

Reputation: 161

Docker /bin/sh: 1: ng: not found (Angular)

I am trying to build a docker image for an Angular app but it crashes on RUN ng build --prod and I get the following error:

/bin/sh: 1: ng: not found
The command '/bin/sh -c ng build --prod' returned a non-zero code: 127

Here is my Dockerfile:

FROM node:13.3.0 AS compile-image
RUN npm install -g yarn
WORKDIR /opt/ng 
COPY package.json yarn.lock ./
RUN yarn
RUN yarn install
COPY . ./ 
RUN ng build --prod
FROM nginx
COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=compile-image /opt/ng/dist/dashboard /usr/share/nginx/html
CMD ["yarn", "start"]

I have no previous experience with docker, so sorry if this is a stupid question.

Upvotes: 14

Views: 22278

Answers (1)

Ry-
Ry-

Reputation: 224856

You might have the Angular CLI installed as a global package when you do normal development, making the ng command available everywhere. It isn’t installed globally in the Docker container, and rather than installing it globally you should use the local version directly:

RUN node_modules/.bin/ng build --prod

Upvotes: 34

Related Questions