This is the fist time I am writing a Dockerfile. I have an application in Angular that connects to different backends (Spring Boot Rest services). I mean to say the spring boot application has been deployed in many different sites/locations. They all have different URLs. These Rest services are already there (I didn't write these rest services). I was getting CORS error when I tried to call these Rest services. So I had to us the below xyx.proxy.conf.json
Below is the configurations I have:
package.json
"scripts": {
"ng": "ng",
"start:localhost": "ng serve --proxy-config localhost.proxy.conf.json",
"start:site1qa": "ng serve --proxy-config site1qa.proxy.conf.json",
"start:site2qa": "ng serve --proxy-config site2qa.proxy.conf.json",
"start:site1prod": "ng serve --proxy-config site1qa.proxy.conf.json",
"start:site2prod": "ng serve --proxy-config site2prod.proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e --proxy-config site1qa.proxy.conf.json"
},
site1qa.proxy.conf.json Note: I must have to use proxy as I am getting CORS error
{
"/RestWeb/*": {
"target": "http://site1qa:8005",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
Angular Service.ts
findAllByModelYear(): Observable<string[]> {
return this.httpClient.get<string[]>('/RestWeb/model/findAllModelYearCodes');
}
I tested the application using below commands in my local pointing to different backends like this:
npm run start:localhost
OR
npm run start:site1qa
OR
npm run start:site2prod
My current Dockerfile is like this:
# Stage 1: Compile and Build angular codebase
# Use official node image as the base image
FROM node:latest as build
# Set the working directory
WORKDIR /usr/local/app
# Add the source code to app
COPY ./ /usr/local/app/
# Install all the dependencies
RUN npm install
# Generate the build of the application
RUN npm run build
# Stage 2: Serve app with nginx server
# Use official nginx image as the base image
FROM nginx:latest
# Copy the build output to replace the default nginx contents.
COPY --from=build /usr/local/app/dist/my-projectt /usr/share/nginx/html
# Expose port 80
EXPOSE 80
Currently am I build like this:
docker build -t dockerangular .
And run like this:
docker run -it -p 8000:80 --name angulardocker1 my-first-app
Question:
How do I pass argument (while building and/or running the application), so I can connect to different sites (as mentioned in package.json i.e. using xyx.proxy.conf.json)