Published: Wed May 17 2023
A sort of distributed hosting service launched in 2020. Ok but what is Fly.io’s competitive advantage? It allows deploying applications to the edge with the ability to select a region(or regions) closest to end users.
Keep in mind Fly.io offers a free tier - Hobby plan with up to 3 VMs BUT it will require a credit card to proceed with.
With all the signup out of the way the first thing required is to install the Fly.io cli, flyctl from here. Next, inside an empty directory on your local machine, create an empty fly.toml file. Lets fit it out with the following for a Pocketbase instance;
app = "my-app-name" # give your app a name
primary_region = "sin" # select a region from fly.io/docs/reference/regions
[build]
image = "spectado/pocketbase" # a docker image from docker hub with pocketbase
[[mounts]]
source = "pb_data" # volume name to store our data
destination = "/pb_data" # mounting location as per docker image
[http_service]
internal_port = 80 # expose app
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
Note, a local docker image can be used but in this case we are instructing Fly.io to use one from docker hub. With all that added and saved, the first command to run is;
fly launch
Select all the defaults, indicating no database is required and make sure to say NO to deploy the app. This will happen after we have created a volume to store our Pocketbase data on for persistence. This can be done with a name as per our toml file under mounts(pb_data);
fly volumes create pb_data --size=1
This will start the process and ask for the region, select the same one as per the toml file(eg “sin”). If an error is shown asking at least 2 volumes are required, you can ignore it and continue with the single one since this is only a ‘hobby’ app and not for production. Next, lets deploy the app with;
fly deploy
To check if everything went to plan, use the following cli commands;
fly apps list # check your app name as per toml file is listed
fly volumes list # check your volume was mounted under ATTACHED VM
If everything looks good, visit your apps url as displayed on the last line of the deploy command(eg my-app-name.fly.dev). Visit your apps url with ‘/_/’ at the end(eg my-app-name.fly.dev/_/) for creating the first required admin account.
To use Pocketbase, include it in your Javascript project;
import PocketBase from 'pocketbase';
const pb = new PocketBase('https://my-app-name.fly.dev');
Visit the Pocketbase docs for further instructions.
Skip all this if you just need a Pocketbase instance and use Pockethost which is completely free!
Back