简体   繁体   English

Docker /bin/sh: 1: ng: 未找到 (Angular)

[英]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:我正在尝试为 Angular 应用程序构建 docker 图像,但它在RUN ng build --prod时崩溃,我收到以下错误:

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

Here is my Dockerfile:这是我的 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.我以前没有使用 docker 的经验,如果这是一个愚蠢的问题,我很抱歉。

You might have the Angular CLI installed as a global package when you do normal development, making the ng command available everywhere.当您进行正常开发时,您可能会将 Angular CLI 作为全局 package 安装,从而使ng命令随处可用。 It isn't installed globally in the Docker container, and rather than installing it globally you should use the local version directly:它没有在 Docker 容器中全局安装,而不是全局安装,您应该直接使用本地版本:

RUN node_modules/.bin/ng build --prod

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM