即使Docker构build映像时安装了angular-cli ng命令,也不会发现这个命令

我试图用angular-cli作为控制器来构build一个应用程序的图像。 在使用ng build --prod命令ng build --prod时, ng build --prod器崩溃。

我试图在全局或本地文件夹上实现angular-cli,但每次调用ng命令时,构build控制台都表示无法在不是angular-cli应用程序的文件夹上构build。

问题是docker构build过程运行在正确的文件夹上ng build 。 这是我的docker文件。

错误信息: The command '/bin/sh -c ng build --prod' returned a non-zero code: 127其他错误信息: /bin/sh: 1: ng: not found

 FROM node:6.9.1 ENV DEBIAN_FRONTEND noninteractive ADD ./ /opt/ RUN cd /opt/ && ls -l ### MYSQL RUN apt-get update && apt-get install -y --no-install-recommends apt-utils \ && apt-get install -y mysql-client libmysqlclient-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # ORACLE #INSTALL LIBAIO1 & UNZIP (NEEDED FOR STRONG-ORACLE) RUN apt-get update \ && apt-get install -y libaio1 \ && apt-get install -y build-essential \ && apt-get install -y unzip \ && apt-get install -y curl #ADD ORACLE INSTANT CLIENT RUN mkdir -p opt/oracle ADD ./oracle/linux/ . RUN unzip instantclient-basic-linux.x64-12.1.0.2.0.zip -d /opt/oracle \ && unzip instantclient-sdk-linux.x64-12.1.0.2.0.zip -d /opt/oracle \ && mv /opt/oracle/instantclient_12_1 /opt/oracle/instantclient \ && ln -s /opt/oracle/instantclient/libclntsh.so.12.1 /opt/oracle/instantclient/libclntsh.so \ && ln -s /opt/oracle/instantclient/libocci.so.12.1 /opt/oracle/instantclient/libocci.so ENV LD_LIBRARY_PATH="/opt/oracle/instantclient" ENV OCI_HOME="/opt/oracle/instantclient" ENV OCI_LIB_DIR="/opt/oracle/instantclient" ENV OCI_INCLUDE_DIR="/opt/oracle/instantclient/sdk/include" RUN echo '/opt/oracle/instantclient/' | tee -a /etc/ld.so.conf.d/oracle_instant_client.conf && ldconfig EXPOSE 30009 ### SQL SERVER RUN npm install sql-cli -g RUN npm install @angular/cli -g RUN npm install typescript -g RUN npm install typings -g RUN npm cache clean && rm -rf ~/.npm RUN cd /opt/ RUN rm -rf node_modules RUN ls -l RUN npm install --production --unsafe-perm RUN npm cache clean RUN cd /opt/ && ls -l RUN ng build --prod # PM2 RUN npm install pm2 -g ENV NODE_ENV=production # UP app CMD cd /opt/ \ && pm2-docker start dist/server/app.js 

当前目录在每个Dockerfile层设置为WORKDIR,所以它放弃你所有的cd 。 所以改变

 RUN cd /opt/ && ls -l RUN ng build --prod 

至:

 WORKDIR /opt/ RUN ng build --prod 

要么:

 RUN cd /opt/ && ng build --prod 

另外,确保npm目录在你的“PATH”variables中。