【问题标题】:angular-cli ng command not found even if it is installed while docker building an image即使在 docker 构建映像时安装了 angular-cli ng 命令,也找不到它
【发布时间】:2019-03-24 19:36:16
【问题描述】:

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

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

问题是 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

【问题讨论】:

    标签: docker dockerfile angular-cli


    【解决方案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”变量中。

    【讨论】:

      【解决方案2】:

      我对 Docker 很陌生,昨晚开始使用它,但遇到了同样的问题。

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

      RUN npm run-script build
      

      这是终端推荐的,它确实有效,让我可以继续构建步骤。 我认为这不是最佳做法吗?非常感谢您的反馈。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-01-08
        • 1970-01-01
        • 2020-08-29
        • 1970-01-01
        • 2021-07-23
        • 2020-07-10
        • 2023-03-22
        相关资源
        最近更新 更多