Answers: <p>Finally managed to generate the docker image for Angular. Here are is the screnshot.</p>
  <p><a href="https://i.sstatic.net/C7SLR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/C7SLR.png" alt="enter image description here" /></a></p>
  <p>I am listing the contents of the Docker File along with the comments that explain the reasoning and my learnings.</p>
  <pre><code># Created by Sridhar Pandurangiah - 29 October 2020
  # This Docker file helps create the containers for the Angular User Interface
  #1 We would like to create from the node image and then add the layers. I had initially started from a base image and proceeded to add Ubuntu, it did not work out as creating a ubuntu from the base involves a lot of work and its rather baseless to start from a base image. Then switched to starting from the Ubuntu image and the problems I faced is documented in this question. So had to start from the node image. Also remember that docker containers have to address a single concern.
  
  FROM node:15.1.0 as ab-suite-image
  
  #Add Information about this image
  LABEL maintainer=&quot;sridhar@st.in&quot;
  LABEL version=&quot;1.0&quot;
  LABEL decsription=&quot;This is a docker image built from the node image and includes angular9 and metronic theme&quot;
  
  #2 Add Angular and other peer dependencies that do not get installed by default to avoid the build from exiting with errors
  RUN npm install -g @angular/cli@9.1.12 @angular/core @angular/common eslint chokidar jquery popper.js tslib --save
  
  # Set environment variables for file locations if required
  
  #3 Set the environment Variable to determine the environment where the application is deployed development | testing | staging | production
  ENV AB_COMPLIANCE_ENV=development
  
  #4 Set the working directory to copy the angular dependencies
  WORKDIR /opt/ng
  
  #5 We don't pull the code from GIT as it would mean storing the private ssh keys on a docker image that can be publicly accessed. This is is not advisable.
  COPY package.json ./
  
  #6 Update project dependencies using package.json. This stage is where we encountered a lot of issues with build failing as the shell scripts were returing errors. the flag --legacy-peer-deps ensures that the npm doesn't throw errors so the docker build continues
  RUN npm install --legacy-peer-deps
  
  #7 Copy all the other project files and build
  COPY . ./
  RUN ng build
  
  
  #8 Configure Volumes if required
  
  #9 Copy start Script if required
  #COPY start.sh /start.sh
  #CMD [&quot;./start.sh&quot;]
  
  #10 Expose Port for the application
  EXPOSE 4200 443
  </code></pre>
  <p>This docker image can be used to for running unit and E2E tests.</p>
  <p>Some literature on the web ask you to install nginx but not advisable. Run nginx on a seperate dedicated container. On production you can build the angular application with the &quot;prod&quot; flag and copy the files so that nginx can serve them.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-11-19T09:10:03.717Z
Answers: 2020-11-19T09:10:03.717Z
Answers: sridhar pandurangiah
Body: <p>I am trying to create an image for my angular application for running unit and e2e tests. I started from the ubuntu image and then installed the other components. My dockerfile has the following statements.</p>
  <pre><code>FROM ubuntu:focal-20201008
  
  RUN apt update &amp;&amp; apt install -y \
      nginx \
      nodejs \
      npm \
      &amp;&amp; npm install -g @angular/cli@9.1.12 \
      &amp;&amp; rm -rf /var/lib/apt/lists/*
  </code></pre>
  <p>When I build the image using</p>
  <pre><code>sridhar@sridhar-HP-Laptop-15-H:~/abui/$ docker build --tag abui .
  </code></pre>
  <p>I get the following message (last few lines pasted here)</p>
  <pre><code>npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
  npm WARN deprecated har-validator@5.1.5: this library is no longer supported
  /usr/local/bin/ng -&gt; /usr/local/lib/node_modules/@angular/cli/bin/ng
  
  &gt; @angular/cli@9.1.12 postinstall /usr/local/lib/node_modules/@angular/cli
  &gt; node ./bin/postinstall/script.js
  
  
  The command '/bin/sh -c apt update &amp;&amp; apt install -y     nginx     nodejs     npm     &amp;&amp; npm install -g @angular/cli@9.1.12     &amp;&amp; rm -rf /var/lib/apt/lists/*' returned a non-zero code: 1
  </code></pre>
  <p>P.S. I don't want to start from the node docker image as of now</p>
  
Comments: CC BY-SA 4.0
Comments: 2020-11-12T16:42:05.087Z
Comments: Have you checked whether the dependency names are all correct? the command returns non-zero code. Probably some syntax error. Try running each of them individually and find which statement is wrong.
Comments: sd1517
Comments: CC BY-SA 4.0
Comments: 2020-11-13T08:00:48.900Z
Comments: These are probably due to several factors
  1. Angular prompts if analytics should be shared with the angular team. Tis should be turned off using ng analytics off
  2. There are several depreciated packages in my case for angular 9.1.12 I had the following : tslint@6.1.3, request@2.88.2, chokidar@2.1.8, har-validator@5.1.5, fsevents@1.2.13, urix@0.1.0, resolve-url@0.2.1 jquery@1.9.1, popper.js@^1.16.1 @angular/common@^9.0.0, @angular/core@^9.0.0, tslib@^1.10.0
Comments: sridhar pandurangiah
Comments: CC BY-SA 4.0
Comments: 2020-11-13T08:00:55.020Z
Comments: Initially tried this with Ubuntu image. Then switched to the node image. But the results are similar but using the node image I get to see the node messages. Most literature on the web suggest installing angular locally within the project and then copying them to the container. That increases the size of the context. But I guess that's the only way out. Still trying out different things. Will post my learnings once I have a working image.
Comments: sridhar pandurangiah
Comments: CC BY-SA 4.0
Comments: 2020-11-13T09:18:20.107Z
Comments: for the first angular prompts you can do somethink like: "set +o pipefail" and then  passing yes while installing angular and then "set -o pipefail". This should make your script run without failures.
Comments: sd1517
Tags: <docker><node.js><npm>
Title: RUN fails while installing Angular on Ubuntu Image
UserDisplayName: sridhar pandurangiah
ThreadText: # RUN fails while installing Angular on Ubuntu Image
  
  (Asked by: username_0 on 2020-11-11)
  
  I am trying to create an image for my angular application for running unit and e2e tests. I started from the ubuntu image and then installed the other components. My dockerfile has the following statements.
  
  ```
  FROM ubuntu:focal-20201008
  
  RUN apt update && apt install -y \
      nginx \
      nodejs \
      npm \
      && npm install -g @angular/cli@9.1.12 \
      && rm -rf /var/lib/apt/lists/*
  
  ```
  
  When I build the image using
  
  ```
  username_0@username_0-HP-Laptop-15-H:~/abui/$ docker build --tag abui .
  
  ```
  
  I get the following message (last few lines pasted here)
  
  ```
  npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
  npm WARN deprecated har-validator@5.1.5: this library is no longer supported
  /usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng
  
  > @angular/cli@9.1.12 postinstall /usr/local/lib/node_modules/@angular/cli
  > node ./bin/postinstall/script.js
  
  The command '/bin/sh -c apt update && apt install -y     nginx     nodejs     npm     && npm install -g @angular/cli@9.1.12     && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 1
  
  ```
  
  P.S. I don't want to start from the node docker image as of now
  
  **Tags:** docker, node.js, npm
  
  > **Comments:**
  > **username_1**: Have you checked whether the dependency names are all correct? the command returns non-zero code. Probably some syntax error. Try running each of them individually and find which statement is wrong.  
  > **username_0**: These are probably due to several factors 1. Angular prompts if analytics should be shared with the angular team. Tis should be turned off using ng analytics off 2. There are several depreciated packages in my case for angular 9.1.12 I had the following : tslint@6.1.3, request@2.88.2, chokidar@2.1.8, har-validator@5.1.5, fsevents@1.2.13, urix@0.1.0, resolve-url@0.2.1 jquery@1.9.1, popper.js@^1.16.1 @angular/common@^9.0.0, @angular/core@^9.0.0, tslib@^1.10.0  
  > **username_0**: Initially tried this with Ubuntu image. Then switched to the node image. But the results are similar but using the node image I get to see the node messages. Most literature on the web suggest installing angular locally within the project and then copying them to the container. That increases the size of the context. But I guess that's the only way out. Still trying out different things. Will post my learnings once I have a working image.  
  > **username_1**: for the first angular prompts you can do somethink like: "set +o pipefail" and then  passing yes while installing angular and then "set -o pipefail". This should make your script run without failures.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-11-19. Score: 1 | Accepted answer
  
  Finally managed to generate the docker image for Angular. Here are is the screnshot.
  
  [![enter image description here](https://i.sstatic.net/C7SLR.png)](https://i.sstatic.net/C7SLR.png)
  
  I am listing the contents of the Docker File along with the comments that explain the reasoning and my learnings.
  
  ```
  # Created by username_0 - 29 October 2020
  # This Docker file helps create the containers for the Angular User Interface
  #1 We would like to create from the node image and then add the layers. I had initially started from a base image and proceeded to add Ubuntu, it did not work out as creating a ubuntu from the base involves a lot of work and its rather baseless to start from a base image. Then switched to starting from the Ubuntu image and the problems I faced is documented in this question. So had to start from the node image. Also remember that docker containers have to address a single concern.
  
  FROM node:15.1.0 as ab-suite-image
  
  #Add Information about this image
  LABEL maintainer="username_0@st.in"
  LABEL version="1.0"
  LABEL decsription="This is a docker image built from the node image and includes angular9 and metronic theme"
  
  #2 Add Angular and other peer dependencies that do not get installed by default to avoid the build from exiting with errors
  RUN npm install -g @angular/cli@9.1.12 @angular/core @angular/common eslint chokidar jquery popper.js tslib --save
  
  # Set environment variables for file locations if required
  
  #3 Set the environment Variable to determine the environment where the application is deployed development | testing | staging | production
  ENV AB_COMPLIANCE_ENV=development
  
  #4 Set the working directory to copy the angular dependencies
  WORKDIR /opt/ng
  
  #5 We don't pull the code from GIT as it would mean storing the private ssh keys on a docker image that can be publicly accessed. This is is not advisable.
  COPY package.json ./
  
  #6 Update project dependencies using package.json. This stage is where we encountered a lot of issues with build failing as the shell scripts were returing errors. the flag --legacy-peer-deps ensures that the npm doesn't throw errors so the docker build continues
  RUN npm install --legacy-peer-deps
  
  #7 Copy all the other project files and build
  COPY . ./
  RUN ng build
  
  #8 Configure Volumes if required
  
  #9 Copy start Script if required
  #COPY start.sh /start.sh
  #CMD ["./start.sh"]
  
  #10 Expose Port for the application
  EXPOSE 4200 443
  
  ```
  
  This docker image can be used to for running unit and E2E tests.
  
  Some literature on the web ask you to install nginx but not advisable. Run nginx on a seperate dedicated container. On production you can build the angular application with the "prod" flag and copy the files so that nginx can serve them.
  
  
  ---
  
  