Deploying a Next.js App to Hetzner with Docker: Complete Guide
Hetzner offers some of the best price-to-performance ratios for VPS hosting. Here is how we deploy our Next.js app with Docker.
Prerequisites
The Dockerfile
We use a multi-stage build: deps (install node_modules), builder (prisma generate + next build), runner (minimal alpine image). The final image is under 200MB.
Docker Compose
Our docker-compose.yml defines two services: the Next.js app and MySQL 8. MySQL data persists in a named volume. The app waits for MySQL to be healthy before starting.
Environment Variables
Copy .env.production.example to .env.production and fill in: DATABASE_URL (pointing to the MySQL container), Clerk keys, Stripe keys, and your domain.
Deployment Steps
docker compose up -d --builddocker compose exec app npx prisma db pushdocker compose exec app npx prisma db seedSSL with Caddy
We recommend Caddy as a reverse proxy — it handles SSL certificates automatically. A simple Caddyfile: yourdomain.com { reverse_proxy app:3000 }
CI/CD
Our GitHub Actions workflow runs lint and build on PRs, then deploys to Hetzner on push to main via SSH.
Related Posts
Sponsor Our Newsletter
Reach thousands of developers who are actively evaluating AI tools, MCP servers, and dev infrastructure. Our weekly newsletter goes to engaged technical decision-makers.
All sponsored content is clearly labeled per our editorial policy.