即使在建立图像的docker中安装了angular-cli ng命令,也找不到它

问题描述 投票:1回答:2

我尝试使用angular-cli作为其控制器为应用程序构建图像。在使用ng build --prod命令的构建时,docker builder崩溃。

我试图在全局或本地文件夹上实现angular-cli,但每次调用ng命令时,构建控制台都说它不能构建一个不是angular-cli应用程序的文件夹。

问题是docker构建过程在右侧文件夹上运行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
docker dockerfile angular-cli
2个回答
1
投票

当前目录在每个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”变量中。


0
投票

我是Docker的新手,昨晚开始玩它,我遇到了同样的问题。

我没有使用ng build(我当时无法使用)我在dockerfile中添加了以下运行命令:

RUN npm run-script build

这是终端推荐的,它确实有效,并允许我继续我的步骤来构建。我认为这不是最佳做法吗?反馈将不胜感激。

© www.soinside.com 2019 - 2024. All rights reserved.