Set up a free PocketBase database with Fly.io
I was playing around with Linode recently to try set up a PocketBase instance then I came across this guide on the PocketBase GitHub discussions.
The whole thing took around ten minutes and I now have a SQLite database I can read/write to.
There’s a lot more I’ll need to do to get a project running but this was one thing I wanted to make sure I could do before progressing.
Anyways I’ll go through the steps I did to get set up so I can refer back to it when I need it again!
A lot of this guide will be verbatim from the GitHub discussion linked earlier!
There’ll be a lot of terminal commands!
Set up PocketBase Dockerfile
First thing I’ll do is set up a project folder on my machine which will have the Docker file in it to run the PocketBase instance.
1# make a directory for the project
2mkdir pocketbase
3# change directory into the folder
4cd pocketbaseThen in the directory I’ll create a Docker file and copypasta the config from the GitHub discussion:
1# create Dockerfile
2touch DockerfileThe contents of the Dockerfile are:
1FROM alpine:latest
2
3ARG PB_VERSION=0.7.6
4
5RUN apk add --no-cache \
6 unzip \
7 # this is needed only if you want to use scp to copy later your pb_data locally
8 openssh
9
10# download and unzip PocketBase
11ADD https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip /tmp/pb.zip
12RUN unzip /tmp/pb.zip -d /pb/
13
14EXPOSE 8080
15
16# start PocketBase
17CMD ["/pb/pocketbase", "serve", "--http=0.0.0.0:8080"]So, from my limited understanding of Docker it looks like this file is
provisioning the latest version of PocketBase from the GitHub releases
page, exposing port 8080 then serving PocketBase from the /pb directory.
Set up Fly.io
I’ll follow the Fly.io install guide, I use Windows Subsystem for Linux (WSL) with Ubuntu so I’ll use the Linux install instructions.
1curl -L https://fly.io/install.sh | shThen use the CLI for signup and login, signup first:
1flyctl auth signupThe CLI then directs me to create an account on Fly.io, I’ll do that then come back to the CLI and login:
1flyctl auth loginSet up Fly.io app
From within the project directory I’ll run the following command to set up the Fly.io app:
1flyctl launchThis will ask me a few questions, I’ll answer them as follows:
1? App Name (leave blank to use an auto-generated name): pocketbase
2? Select region: lhr (London, United Kingdom)
3? Would you like to set up a Postgresql database now? No
4? Would you like to deploy now? NoThe CLI creates a fly.toml in the same location as the Dockerfile
file which I’ll need to edit now to add the storage volume.
Create free 1GB storage volume
I’ll use the Fly.io CLI to create a storage volume, pb_data is where
PocketBase writes to:
1flyctl volumes create pb_data --size=1I’m prompted to pick a region, I’ll pick the same one I picked when I
run the flyctl launch command.
Now I need to add the [mounts] section to the fly.toml file:
1[mounts]
2 destination = "/pb/pb_data"
3 source = "pb_data"Here’s what my full TOML file looks like after adding in the [mounts] config:
1# fly.toml file generated for pocketbase on 2022-10-02T17:22:41+01:00
2
3app = "pocketbase"
4kill_signal = "SIGINT"
5kill_timeout = 5
6processes = []
7
8[env]
9
10[experimental]
11 allowed_public_ports = []
12 auto_rollback = true
13
14[mounts]
15 destination = "/pb/pb_data"
16 source = "pb_data"
17
18[[services]]
19 http_checks = []
20 internal_port = 8080
21 processes = ["app"]
22 protocol = "tcp"
23 script_checks = []
24 [services.concurrency]
25 hard_limit = 25
26 soft_limit = 20
27 type = "connections"
28
29 [[services.ports]]
30 force_https = true
31 handlers = ["http"]
32 port = 80
33
34 [[services.ports]]
35 handlers = ["tls", "http"]
36 port = 443
37
38 [[services.tcp_checks]]
39 grace_period = "1s"
40 interval = "15s"
41 restart_limit = 0
42 timeout = "2s"Deploy
Now to deploy the app to Fly.io with the following command:
1flyctl deployThat’s it!
Now I can access the PocketBase instance on Fly.io at https://pocketbase.fly.dev/_/ there’s an initial setup page which
I’ll go through to set up the an admin user.
I can now start creating collections and adding users!
Next steps
I’ll be playing around with the PocketBase JavaScript SDK to use in an as yet undetermined SvelteKit project.
There’s still the backup and downloading of data I need to check out, but for a quick and easy way to get a PocketBase instance up and running this is a great way to do it!
That’s it, this guide is here primarily for me to refer back to when I need to do this again, if you find it useful feel free to share it!
There’s lots more useful information covered in the GitHub discussion as well which I’ll be referring to in the future!
There's a reactions leaderboard you can check out too.
Sign up for the newsletter
Want to keep up to date with what I'm working on?
Join other developers and sign up for the newsletter.
I care about the protection of your data. Read the Privacy Policy for more info.