Answer a question

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.

Answers

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
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐