๐Ÿš€

Deploy with Docker

๐Ÿ‘จโ€๐Ÿณ Chefโฑ๏ธ 40 minutes

๐Ÿ“‹ Suggested prerequisites

  • โ€ขDocker Compose
  • โ€ขBasic VPS

What you'll build

A complete production environment where your Next.js application runs in Docker containers alongside PostgreSQL, Redis, and Nginx as a reverse proxy. You'll create an optimized multi-stage Dockerfile, a docker-compose.yml that orchestrates all services, and automatic HTTPS configuration with Let's Encrypt. When finished, you'll have your app running on a real VPS (DigitalOcean, Hetzner) with your own domain and SSL certificate, ready to receive real users.


Requirements

  • VPS (DigitalOcean, Hetzner, etc.)
  • Docker installed on VPS
  • Domain (optional but recommended)

Step 1: Ask an AI for the setup

I need to deploy a Next.js app with:
- Optimized Dockerfile (multi-stage)
- docker-compose.yml with:
  - Next.js App
  - PostgreSQL
  - Redis
  - Nginx as reverse proxy
- HTTPS with Let's Encrypt
- Deploy scripts

Give me all necessary files.

Dockerfile

FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/static ./.next/static
CMD ["node", "server.js"]

Deploy

ssh user@server "cd /app && git pull && docker compose up -d --build"

Next step

โ†’ CI/CD with GitHub Actions