This guide will show you how to deploy your supastarter SaaS to fly.io in minutes. And the best part? You can actually start for free thanks to the generous free tier of fly.io.
Why host your SaaS on fly.io?
Self-hosting your SaaS app as a docker image allows you to have complete control over your server environment. It ensures better privacy, contributes to cost savings if managed correctly, and offers you the flexibility to customize your server setup to suit your specific needs. It can also give your application a performance boost compared to hosting on a serverless platform like Vercel, since it removes cold starts.
Setup Next.js app for docker deployment
Before you can deploy your application to fly.io, you need to configure your project to be built as a standalone app and create a Dockerfile, so that you can run your application as a docker image on the fly.io platform.
You can find a working example of this on the feature/docker-deploy
branch in the supastarter repository.
First add the following config to your apps/web/next.config.js
:
Setup docker configuration for the Next.js app
Next, create a Dockerfile in the root of your Next.js app (apps/web/Dockerfile
) with the following content:
In the root of the supastarter project, also add a .dockerignore
file with the following content:
And that’s all the changes necessary! Now you can build your app as a docker image and deploy it anywhere you can run docker images.
Running your app locally with Docker
If you have Docker installed on your local machine, you can test the docker image by simply running the following commands from your project’s root:
To fully use the application, you need to pass the necessary environment variables you have defined in your .env.local
file to the container.
Deploying your application to Fly.io
Make sure you have an account on Fly.io before continuing. You can sign up for free at fly.io.
To deploy your application with Docker to fly.io simply install the Fly CLI and run the following command from your project’s root:
Follow the steps in the CLI and configure the used port to 3000
in the deployment configuration and you should have a running instance of your app within a few minutes on fly.io.
And that's all it takes to deploy your supastarter SaaS with fly.io! If you have questions, feedback or feature requests, feel free to reach out to us on Twitter.
The ultimate starter kit to build a scalable and production-ready SaaS
Save endless hours of development time and focus on what's important for your customers with our SaaS starter kits for Next.js 14 and Nuxt 3
Get startedStay up to date
Sign up for our newsletter and we will keep you updated on everything going on with supastarter.