Below is the logic in my docker file. I am using nginx to build the application.
FROM node:14-alpine as builder
COPY package.json ./
RUN npm install && mkdir /app && mv ./node_modules ./app
WORKDIR /app
COPY . .
RUN npm run build
FROM nginx:1.16.0-alpine
COPY --from=builder /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]
Below is the nginx.conf file
server {
listen 3000;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
location /api {
# rewrite /api/api(.*) /$1 break;
proxy_pass http://${backend_host}:${backend_port}/api;
}
include /etc/nginx/extra-conf.d/*.conf;
}
backend_host and backend_port in the proxy_pass URL will be provided while deploying the image using Deployment file.
Is this possible? If not is there any alternative way for this?