dockerize angular app
I'am trying to create one image with angular side and another with netcore side. Trying for angular, dockerfile:
FROM node:12.16.1 AS compile-image WORKDIR /opt/ng COPY package.json ./ RUN npm install ENV PATH="./node_modules/.bin:$PATH" COPY . ./ RUN ng build --prod FROM nginx COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf COPY --from=compile-image /opt/ng/dist/fichamedica /usr/share/nginx/html
throws:
For the out of memory, changed
"ng build --prod"
for
"node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --prod"
and throws:
btw, build commands go fine locally.
Any ideas?
I had to allocate more memory to Docker, after that (and long time waiting) it finished successfully
@luisp88 the Dockerfile in the first post does not work for me.

I don't know how your builder finds .conf file
I was focusing in build problem, so probably after resolving that I encountered other problems (as the one you're showing) and updated the dockerfile. Use this instead:
### STAGE 1: Build ###
FROM node:12.16.1 AS build
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install -g @angular/cli
RUN npm install
COPY . .
RUN npm run ng-high-memory-integ
### STAGE 2: Run ###
FROM nginx
COPY --from=build /usr/src/app/dist/FichaMedica /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
PS: I started using custom commands for ng build because I had memory problems for compiling with production target. ng-high-memory-integ in my package.json: node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng build --configuration=production (or prod)
Thank you @luisp88, but my dockerfile:
### STAGE 1: Build ###
FROM node:12.16.1 AS build
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install -g @angular/cli
RUN npm install
COPY . .
RUN npm run node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng build --configuration=production
### STAGE 2: Run ###
FROM nginx
COPY --from=build /usr/src/app/dist/MyApp /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
returns this error

What is your Dockerfile for ASP.NET Core project? I am experiencing this issue: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSMissingAllowOrigin ASP.NET Core projects (.HttpApi.Host and .IdentityServer) runs inside kestrel. All three projects (IdentityServer, HttpApi.Host and Angular) are deployed to separated containers with dedicated static IP inside Docker environment.
Just try node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng build in your dockerfile (without npm run).
Allocating max_old_space_size is not mandatory (I had to use it because I was short in memory for build command). You can use ng build --prod or something else directly.
You can use npm run X when you define X in your package.json's "scripts" section (like an alias). Example: npm run build if your scripts section has "build": "ng build",
Also, use the image version you need (in my case, I am using node 12.16.1)
Thanks @luisp88, but there is still error on the last step:
How can I determine where is nginx.conf file?
Would you please share Dockerfile for .NET Core projects (.HttpApi.Host and .IdentityServer)? I suspect that kestrel webserver has to do with "CORS Missing Allow Origin"?
Sorry, forgot to paste nginx configuration file in repo's root
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}
@luisp88, lease ping me on email [email protected] for more detailed situation. :) Thank you.
Well, I dockerized Angular, but I have question. Is it somehow possible to set environment variables (which are inside environment.ts, environment.ts) during building on Docker installation? It would be really annoying to build Angular Docker image for each client separately.
@luisp88 how to achive this in Dockerfile
- How to replace on the fly (when image is taken from Docker registry) and building on server:
- environment.oAuthConfig.issuer
- environment.apis.default.url
- How to run (nginx inside Angular container)
This is essential, because I do not want to create Angular image for each customer.
Thank you.