How to redeploy frontend nginx

Hello, maybe someone could explain me:

I am building my Angular app where in Dockerfile I:

FROM node:22.1.0 AS build
<...>
# install npm dependencies, build application
<...>

FROM nginx:1.25.5 AS runtime
COPY --from=build /usr/src/root/dist/apps/browser /usr/share/nginx/html

And for the docker-compose.yml:

services:
  frontend:
    image: frontend
    restart: unless-stopped
    depends_on:
      - backend
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
  <...>

Now when redeploying the backend, everything is understandable - I run new backend image (via --scale and --no-recreate, so both current and new images are running), then kill the current container to only serve from new one.

What I do not understand is how exactly to perform the frontend redeploy? Do I need to create two services frontend and nginx? Or how exactly to achieve this? As I understand now the files are under /usr/share/nginx/html directory in the frontend image? I cannot start a new frontend image (as compared to backend), since I specified a port.

I though about creating nginx and frontend different images, then the frontend image contains the files its serving and I can redeploy that? But then how to tell nginx service to take frontend files from that service? Please, someone enlighten me on this, I am lost with this. Maybe someone has a working example on this? Cheers.

You need to re-build and re-deploy your frontend image, which is nginx serving the built angular html files.

What’s your issue with re-deploying frontend vs backend? Compose usually stops old, then starts new. For swarm there is update-order: stop-first.

You could also run nginx standalone and bind mount the html folder from server/node, then you just manually drop the updated files into the folder.

Hi, I use zero downtime redeploy script, which basically runs another image while the current is running and stops it only when new one is fully functional. The problem is that I cannot start another instance of my frontend image, since it has assigned port. I don’t understand how to keep nginx running and only redeploy frontend image? The scenario must be the same as for the backend - I launch new frontend image (the current nginx must be running and serving the old frontend), then new frontend image must start. If it was successful, I destroy the old one and the nginx redirects traffic to this new one (all this without downtime).

Zero downtime is not possible in your scenario.

We run nginx-proxy or Traefik (example, can support Swarm) as proxy in front of our Docker services, that way we can re-deploy services with start-first, do a rolling update without service interruption.

And to re-deploy proxies with new version, we have a managed load balancer in front.

1 Like

Thanks, I will get nginx-proxy in front of other services.