Host for free on Fly.io #537
Replies: 34 comments 107 replies
-
For sending emails, the following providers have free options:
|
Beta Was this translation helpful? Give feedback.
-
Awesome write! This will be an excellent resource for people getting into Pocketbase. Are you also going to add an entry in the FAQ linking here? I think that would be a good place, instead of people combing through the discussions for a solution. |
Beta Was this translation helpful? Give feedback.
-
Great! It would you really nice if you can also describe how can we get a data backup. Let's say access |
Beta Was this translation helpful? Give feedback.
-
Here's another Docker approach that builds a custom binary as part of Note: In theory, you should be able to cross-compile (#537 (reply in thread)) but if you don't know the target architecture or don't want to worry about it changing, this solution will work. 1. Create a custom PocketBase build:
// ./pocketbase.go
package main
import (
"log"
"github.com/pocketbase/pocketbase"
)
func main() {
app := pocketbase.New()
if err := app.Start(); err != nil {
log.Fatal(err)
}
} // ./go.mod
module pocketbase 2 Create the Dockerfile:FROM alpine:latest
RUN apk add -v build-base
RUN apk add -v go
RUN apk add -v ca-certificates
RUN apk add --no-cache \
unzip \
# this is needed only if you want to use scp to copy later your pb_data locally
openssh
# Copy your custom PocketBase and build
COPY ./pocketbase-custom /pb
WORKDIR /pb
# Note: This will pull the latest version of pocketbase. If you are just doing
# simple customizations and don't have a local build environment for Go,
# leave this line in.
# For more complex builds that include other dependencies, remove this
# line and rely on the go.sum lockfile.
RUN go get github.com/pocketbase/pocketbase
RUN go build
WORKDIR /
EXPOSE 8080
# start PocketBase
CMD ["/pb/pocketbase", "serve", "--http=0.0.0.0:8080"] Let me know what you think! Tested and working on fly.io. |
Beta Was this translation helpful? Give feedback.
-
Deploy with Litestream with PocketBase as a FrameworkI just finished an example repo here https://github.com/TylerSustare/pocketbase-framework-litestream The biggest difference is using the Dockerfile to launch litestream with our custom Go binary as the sub process. |
Beta Was this translation helpful? Give feedback.
-
With fly workers you can turn the Pocketbase into Serverless if you use fly.io. There is a way to also do this on GCP Cloud Run also using volumes also. So if the app has no users then it shuts down ( which is configurable ). When a new request comes through it starts is back up in about half a second by simple rebooting the fire tacket instance and remounting the volume. Blog and example code here: It would be great to combine Serverless with S3 backup / restore but no one has gotten that far yet |
Beta Was this translation helpful? Give feedback.
-
Thanks for this guide! When i ran: |
Beta Was this translation helpful? Give feedback.
-
For anyone still following this, I added a reference to this discussion at https://github.com/benallfree/awesome-pocketbase. I think it would be great to maybe start adding Dockerfiles to awesome-pocketbase, perhaps that could be a centralized place where various configurations could live. |
Beta Was this translation helpful? Give feedback.
-
Hi, Thanks for this solution, but I'm trying to add my pb_data to Dockerfile without results. This is my Dockerfile
I just add
I've pb_data local directory in same Dockerfile directory, but when app is deployed, always show installer view. |
Beta Was this translation helpful? Give feedback.
-
Are there any other option besides fly.io because it needs credit card, and being student I don't have at all. @benallfree |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for this helpful guide ✌️ I just want to add that now you can download your database using fly CLI. You can find more information here: https://fly.io/docs/flyctl/ssh-sftp-get/. To use this feature, navigate to your project's folder, where your |
Beta Was this translation helpful? Give feedback.
-
Hi. I can not use fly.io because of credit card. I'm trying to use render.com free web service but it fails. I don't know what's the problem. I just create a github repo with dockerfile and connected to render website. The logs says docker image is built and points to urls for admin & api s but above in dashboard says failed. |
Beta Was this translation helpful? Give feedback.
-
is there any tutorial for deploying on railway? |
Beta Was this translation helpful? Give feedback.
-
What if you already have a large database locally?? How can you get that onto fly.io? |
Beta Was this translation helpful? Give feedback.
-
If anyone here is using an M1 Mac for their development, and running into issues with deployment, this is the workaround I managed to find.
|
Beta Was this translation helpful? Give feedback.
-
This is how I was able to run my local migrations file on the server to set up my database # this will register a ssh key with your local agent (if you haven't already)
flyctl ssh issue --agent
# proxies connections to a fly VM through a Wireguard tunnel
flyctl proxy 10022:22
# run in a separate terminal to copy local pb_migrations directory onto server
# might need to remove [localhost]:10022 from ~/.ssh/known_hosts if you get a WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! since the key changes all the time
scp -r -P 10022 pb/pb_migrations root@localhost:/pb/pb_migrations
# in another separate terminal, ssh into machine
fly ssh console
#run migration
/pb/pocketbase migrate up |
Beta Was this translation helpful? Give feedback.
-
Hi @ganigeorgiev, this is an excellent guide, I now have my app successfully hosted on Fly.io and deploying in 🚀 time 🎁 ! One thing I've noticed, the request logs User IP turns out to be the same and be a Fly.io one, pretty sure some resolution on the request headers might have to be done. Is there anyway I can achieve it my end, like rewrite to one to another? It's also being cloudflare proxied (but I get the same with it on/off) so might have to do the same there too. Many thanks |
Beta Was this translation helpful? Give feedback.
-
Does anyone else get?
Or does the connection limit just need increased in the toml? |
Beta Was this translation helpful? Give feedback.
-
you can host it on railway now https://railway.app/changelog/2023-06-23-volumes-priority-boarding |
Beta Was this translation helpful? Give feedback.
-
https://pockethost.io allows you to host for free (not self-hosted) until they hit version 1.0. From then on, it seems it'll be a pay-as-you-go https://pockethost.io/docs/overview/faq/ |
Beta Was this translation helpful? Give feedback.
-
Details
I did this, but the things keeps shutting down for some reason, the dashboard shows "deployed" but the pocketbase db just goes down without any reason |
Beta Was this translation helpful? Give feedback.
-
I'm curious what happens during a deploy, especially when a migration is applied? Looks like the default on fly.io is a rolling deploy, where a second instance is spun up alongside the first, then traffic is switched once it's ready. If there are writes ocuring on the first instance during a migration, what will occur? |
Beta Was this translation helpful? Give feedback.
-
I was trying to set up CORS by appending [http_service.http_options.response.headers]
Access-Control-Allow-Origin = "<your-client-url>" Don't know if this is how it is supposed to be but putting this here in case anyone else runs into this. |
Beta Was this translation helpful? Give feedback.
-
From my understanding a new instance is created for a deploy. I wonder if that means there is downtime when doing a deploy as the persistent storage is switched between instances. Probably just need to give it a go if no one else has experience!
|
Beta Was this translation helpful? Give feedback.
-
Is there anyone who has recently deployed with fly.io version-0.1.127? Or @ganigeorgiev can you please update this resource based on the lastest flyctl v0.1.127. They have updated the whole system. After entering the
in fly.toml file. |
Beta Was this translation helpful? Give feedback.
-
Anyone knows how to connect to the Fly instance via .internal links? https://fly.io/docs/reference/private-networking/#fly-io-internal-addresses Same on Railway. Both use IPv4 on external links and IPv6 on internal links |
Beta Was this translation helpful? Give feedback.
-
My app successfully deployed but when I logged in as admin none of my data was on the remote host.
Am I missing anything else? When I run my service via docker locally the data shows up. |
Beta Was this translation helpful? Give feedback.
-
First of all, all the kudos I have go to Pocketbase-- amazing project. I've built an app in Go using PB as a framework, and I think the instructions above need to include the additional steps necessary if using PB as a framework. I am not sure what I need to do in order to properly deploy my app-- I followed the instructions but my homepage returns I created the volume 'pb_data' on fly.io, and my fly.toml is:
My Dockerfile:
My .dockerignore:
And this is my project structure:
edit: I also have this in main.go:
|
Beta Was this translation helpful? Give feedback.
-
I've followed the instructions, updated the versions in the Dockerfile and uncommented the However, when accessing the deployed version, it always presents me with the installer screen. Is there something I'm missing or doing wrong? Thanks
# fly.toml app configuration file generated for abc on 2024-05-10T07:00:16+01:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'abc'
primary_region = 'lhr'
[build]
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']
[[vm]]
memory = '2gb'
cpu_kind = 'shared'
cpus = 1 |
Beta Was this translation helpful? Give feedback.
-
This was requested several times in #498, #432, #328 and others.
Note 1: There will be an official Docker image when PocketBase reach a more stable release
Note 2: I didn't spend too much time exploring all Fly.io configurations so maybe there is a better/easier way to do it.
Note 3: Fly.io has a 60s timeout for idle connections, so you may get periodically errors in the console when using the realtime service. You can ignore them, since the SDK handles the reconnect automatically (#642).
1. Create the PocketBase Dockerfile:
2. Install Flyctl
Follow the installation instructions from https://fly.io/docs/hands-on/install-flyctl/.
Run
flyctl auth signup
to create a Fly.io account (email or GitHub).Run
flyctl auth login
to login.The above commands will open a browser window to authenticate with your Fly account.
If you see a screen saying to enter your billing details you can ignore it (as of now Fly has both free and paid regions; more on that see below).
3. Launch (aka. machine setup)
Navigate to the directory where the Dockerfile from 1) was created.
Run
flyctl launch --build-only
(optionally you can specify--dockerfile
if you are running from different directory).This will prompt you a question in the terminal like:
Type
y
to adjust the settings to the free allowance. This will open the following page:In the above page you need to change 2 mandatory things to enable the free plan:
*
).Click on the "Confirm Settings" button at the bottom and after this a
fly.toml
configuration file will be created in your working directory.4. Create and mount 1GB free persistent volume
Run
flyctl volumes create pb_data --size=1
.You may get a warning like:
Type
y
to confirm.And then it should prompt you to select a region - preferably choose the same region as in 3).
Once finished, open your
fly.toml
and add somewhere at the root level the followingmounts
config:Your final
fly.toml
should look something like this:5. Deploy
Run
flyctl deploy
and that's it!To access your PocketBase dashboard navigate to
https://YOUR_APP_NAME.fly.dev/_/
.To deploy new configuration/image changes, just run
flyctl deploy
again.Backup and downloading a copy of your
pb_data
Fly.io will even create a daily snapshot automatically for your volume (it will be kept for 5 days) - https://fly.io/docs/reference/volumes/#snapshots-and-restores.
To download a copy of your remote
pb_data
directory to your local machine, you could run the following commands in 2 separate terminals:Beta Was this translation helpful? Give feedback.
All reactions