Back to Blogs
    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.

    Zero-Downtime Docker Compose Deployments with GitHub Actions & Nginx Reverse Proxy

    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:

    Dockerfile
    # Stage 1: Dependencies
    FROM node:20-alpine AS deps
    WORKDIR /app
    COPY package*.json ./
    RUN npm ci
     
    # Stage 2: Builder
    FROM node:20-alpine AS builder
    WORKDIR /app
    COPY --from=deps /app/node_modules ./node_modules
    COPY . .
    ENV NODE_ENV=production
    RUN npm run build
     
    # Stage 3: Runner
    FROM node:20-alpine AS runner
    WORKDIR /app
    ENV NODE_ENV=production
    RUN addgroup --system --gid 1001 nodejs && \
    adduser --system --uid 1001 nextjs
     
    COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
    COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
    USER nextjs
    EXPOSE 3000
    CMD ["node", "server.js"]

    2. Automated GitHub Actions Pipeline

    Create .github/workflows/deploy.yml:

    YAML
    name: Production CI/CD Pipeline
     
    on:
    push:
    branches: [main]
     
    jobs:
    test-and-build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
    with:
    node-version: 20
    cache: 'npm'
    - run: npm ci && npm run build
    deploy:
    needs: test-and-build
    runs-on: ubuntu-latest
    steps:
    - name: Deploy to VPS via SSH
    uses: appleboy/ssh-action@v1.0.3
    with:
    host: ${{ secrets.SERVER_HOST }}
    username: ${{ secrets.SERVER_USER }}
    key: ${{ secrets.SERVER_SSH_KEY }}
    script: |
    cd /opt/portfolio
    git pull origin main
    docker compose pull
    docker compose up -d --remove-orphans
    docker 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.

    Sayem Molla

    Full-Stack & AI Systems Engineer (Former Co-Founder @ Softxet). Architecting autonomous AI agents, enterprise RAG pipelines, high-concurrency Python/FastAPI microservices, and modern Next.js 16 platforms.

    SYSTEM: ONLINE (DHAKA, BD)

    Direct Contact

    +880 1704878051

    developersayem012@gmail.com

    Dhaka, Bangladesh

    Stay Connected

    Get updates on new production projects and technical insights.

    © 2026 Sayem Molla. All Rights Reserved.

    Zero-Downtime Docker Compose Deployments with GitHub Actions & Nginx Reverse Proxy | Sayem Molla