Blog
Cloud & DevOps2024-07-1010 min

Self-hosting with Coolify and Docker: why we left Vercel for production

After years using managed platforms, we migrated all our projects to self-hosted infrastructure with Coolify. This is what we gained, lost and learned.

The moment Vercel stopped making sense

Vercel is an excellent product. But there is a point on the cost/benefit curve where self-hosting starts winning. For us that point came when we started having projects with their own databases, background workers, Go services, and the need for control over email infrastructure.

The combination of Vercel + Supabase + Railway + Resend for a single project cost several times what a Hetzner VPS costs, where all those services fit.

What Coolify is

Coolify is an open source self-hosting platform that runs on your own VPS. It manages Docker container deployments, domain and SSL configuration, environment variables, logs and basic monitoring from a web UI.

What differentiates it from installing Docker directly: UI to manage all services from one panel, GitHub integration for automatic deployments via webhook, automatic SSL certificate management with Let's Encrypt, native database service support with automatic S3 backups.

Our VPS architecture

Our current setup on Hetzner CPX31 (4 vCPUs, 8GB RAM, 160GB NVMe): Coolify as orchestrator, PostgreSQL with daily S3 backups, and Caddy as reverse proxy that terminates SSL and forwards to the corresponding container by domain.

The Dockerfile that works with Next.js standalone

Next.js standalone output generates a Node.js server that does not depend on node_modules to run. The multi-stage Dockerfile has three stages: deps, builder, and runner. The entrypoint runs prisma migrate deploy before starting the Node server.

Real cost numbers

Hetzner CPX31 VPS: 12 euros/month. On that VPS everything runs: 4 Next.js applications, 1 Go service, PostgreSQL with 4 databases, automatic backups, and Coolify itself. The equivalent on managed platforms would be 150-300 euros/month.