2

I have tried to build an image for an app with angular-cli as its controller. In build time with ng build --prod command, the docker builder crash.

I have tried to implement angular-cli on global or local folder, but everytime ng command is called, build console says that it cant build on a folder that is not an angular-cli app.

The problem is that docker build process run ng build on the right folder. Here is my docker file.

Error message: The command '/bin/sh -c ng build --prod' returned a non-zero code: 127 Other error message: /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

2 Answers 2

4

The current directory is set to WORKDIR in each Dockerfile layer so it discards whatever you cd. So change

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

To:

WORKDIR /opt/
RUN ng build --prod

Or:

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

Also, make sure that the npm directory is in your "PATH" variable.

Sign up to request clarification or add additional context in comments.

Comments

1

I am very new to Docker and started playing around with it last night and I came across the very same problem.

I did not use ng build ( i could not get it working at the time) I added the following run command in my dockerfile:

RUN npm run-script build

This was recommended by the terminal and it did work and allow me to continue my steps to build. I don't think that this is best practice? Feedback would be greatly appreciated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.