DevOps & Cloud Oct 25, 2026
Zero-Downtime Docker Compose Deployments with GitHub Actions & Nginx Reverse Proxy
A step-by-step production blueprint for rolling out automated CI/CD deployment pipelines on Linux VPS servers using Docker multi-stage builds and blue-green Nginx proxying.
The Pitfalls of Manual Deployments
Manual SSH deployments, direct git pulls on production servers, and raw container restarts cause downtime, broken dependencies, and human error.
In this guide, we engineer an automated CI/CD pipeline that tests, containerizes, pushes, and seamlessly deploys full-stack applications with zero user-facing downtime.
1. Multi-Stage Dockerfile Optimization
A production container must be lightweight, secure, and run under non-root permissions:
DockerfileDockerfile# Stage 1: DependenciesFROM node:20-alpine AS depsWORKDIR /appCOPY package*.json ./RUN npm ci# Stage 2: BuilderFROM node:20-alpine AS builderWORKDIR /appCOPY /app/node_modules ./node_modulesCOPY . .ENV NODE_ENV=productionRUN npm run build# Stage 3: RunnerFROM node:20-alpine AS runnerWORKDIR /appENV NODE_ENV=productionRUN addgroup --system --gid 1001 nodejs && \adduser --system --uid 1001 nextjsCOPY /app/.next/standalone ./COPY /app/.next/static ./.next/staticUSER nextjsEXPOSE 3000CMD ["node", "server.js"]
2. Automated GitHub Actions Pipeline
Create .github/workflows/deploy.yml:
YAMLYAMLname: Production CI/CD Pipelineon:push:branches: [main]jobs:test-and-build:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- uses: actions/setup-node@v4with:node-version: 20cache: 'npm'- run: npm ci && npm run builddeploy:needs: test-and-buildruns-on: ubuntu-lateststeps:- name: Deploy to VPS via SSHuses: appleboy/ssh-action@v1.0.3with:host: ${{ secrets.SERVER_HOST }}username: ${{ secrets.SERVER_USER }}key: ${{ secrets.SERVER_SSH_KEY }}script: |cd /opt/portfoliogit pull origin maindocker compose pulldocker compose up -d --remove-orphansdocker image prune -af
Results
With this setup, every git push to main runs complete tests, builds immutable containers, and deploys updates seamlessly with zero downtime.