I am having a couple of problems running my container
Steps:> ng build --watch
This is ok
build image > docker build -t pblah-angular -f nginx.prod.dockerfile .
This is also ok
run container > docker run -d -p 8080:80 pblah-angular
This is serving the page, but not making the backend call, as it is not using the port of backend server. This is the problem
I have proxy.conf.json with target something like localhost:9001
and start npm start which uses "start": "ng serve --disable-host-check --proxy-config proxy.conf.json"
This works well, as this is not container
But How can I tell docker run also to use the proxy conf?
Second Problem: I deployed to Google cloud, and it fails with below error. I am not using any variable. what is PORT issue there? How to deploy angular to Cloud Run
Ready condition status changed to False for Revision pblah-00002-gov with message: Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information.
New Updates: I used npm start to test the frontend. It used the proxy.conf.json via package.json 's start command --proxy-config
So it worked
Now I created container and running on nginx I was in the illusion that it was working...tried lots of things docker-compose etc...or overlooked thinking 8080 is working than 4200
A little research told me that I need to do something in nginx.config
So updated dockerfile to have that extra CMD(the last one)
RUN npm run build -- --prod
##### Stage 2
FROM nginx:alpine
# VOLUME /var/cache/nginx
COPY --from=node /app/dist/pyui /usr/share/nginx/html
COPY ./config/nginx.conf /etc/nginx/conf.d/default.conf
COPY proxy.conf.json /etc/nginx/conf.d/
CMD ["nginx", "-g", "daemon off;"]
and updated nginx.config with upstream section and the /server section. Still not working "locally", If workes, I will then update for cloudrun
upstream springboot
{
server localhost:9001 max_conns=10;
}
server {
listen 0.0.0.0:80;
listen [::]:80;
default_type application/octet-stream;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
client_max_body_size 256M;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.html =404;
}
location /server {
proxy_pass http://springboot;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
}
}