docker - 即使在 docker 构建镜像时安装了 angular-cli ng 命令,也未找到该命令

标签 docker dockerfile angular-cli

我尝试为一个以 angular-cli 作为 Controller 的应用程序构建一个图像。在构建时使用 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

最佳答案

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

关于docker - 即使在 docker 构建镜像时安装了 angular-cli ng 命令,也未找到该命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44104160/

相关文章:

docker - 是否可以通过在其 docker 容器之一上执行命令来关闭主机?

docker - 无法在 Windows 10 上使用 Docker Toolbox 共享/挂载卷

docker - Heroku 上的 .Net Core 和 Docker

bash - 是否可以将Dockerfile中的ENV变量与正则表达式或包含之类的类似内容进行比较?

docker - 安装PHP扩展的依赖项

angular-cli:使用环境变量的条件导入

angular - Electron Angular2(angular-cli)要求内部模块失败

node.js - Node - 设置 angular-cli 环境

docker - AzureDevops 在构建 Dockerfile 时找不到 csproj 文件

drupal - Docker和Drupal 8-settings.php