Deploying a PocketBase App
Introduction
PocketBase is an open-source backend-as-a-service written in Go, bundling database, auth, and file storage with a REST/Realtime API. Deploying PocketBase with a Dockerfile on Klutch.sh provides reproducible builds, managed secrets, and persistent storage for data and uploads—all configured from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample API usage, and production tips.
Prerequisites
- A Klutch.sh account (sign up)
- A GitHub repository containing your PocketBase Dockerfile (GitHub is the only supported git source)
- Storage sizing for database files, uploads, and logs
For onboarding, see the Quick Start.
Architecture and ports
- PocketBase serves HTTP on internal port
8090; choose HTTP traffic. - Persistent storage is required for database files and uploads.
Repository layout
pocketbase/├── Dockerfile # Must be at repo root for auto-detection└── README.mdKeep secrets out of Git; store them in Klutch.sh environment variables.
Installation (local) and starter commands
Validate locally before pushing to GitHub:
docker build -t pocketbase-local .docker run -p 8090:8090 pocketbase-localDockerfile for PocketBase (production-ready)
Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):
FROM alpine:3.19
ENV PORT=8090 \ POCKETBASE_VERSION=0.21.0
WORKDIR /pb
RUN apk add --no-cache ca-certificates curl \ && curl -L -o pocketbase.zip https://github.com/pocketbase/pocketbase/releases/download/v${POCKETBASE_VERSION}/pocketbase_${POCKETBASE_VERSION}_linux_amd64.zip \ && unzip pocketbase.zip -d /pb \ && rm pocketbase.zip
EXPOSE 8090CMD ["/pb/pocketbase", "serve", "--http=0.0.0.0:8090"]Notes:
- Pin
POCKETBASE_VERSIONto a specific release for stability; update intentionally. - Add
apk add --no-cache tzdataif you need timezone data.
Environment variables (Klutch.sh)
Set these in Klutch.sh before deploying:
PORT=8090- Optional:
PB_ENCRYPTION_KEY=<secure-random>(if you use encryption),PB_LOG_LEVEL=info,PB_DATA_DIR=/pb/pb_data
If you deploy without the Dockerfile and need Nixpacks overrides (rare for prebuilt Go binaries):
NIXPACKS_START_CMD=/pb/pocketbase serve --http=0.0.0.0:8090
Attach persistent volumes
In Klutch.sh storage settings, add mount paths and sizes (no names required):
/pb/pb_data— database files and uploads./pb/logs— optional logs if written to disk.
Ensure these paths are writable inside the container.
Deploy PocketBase on Klutch.sh (Dockerfile workflow)
- Push your repository—with the Dockerfile at the root—to GitHub.
- Open klutch.sh/app, create a project, and add an app.
- Select HTTP traffic and set the internal port to
8090. - Add the environment variables above, including any encryption or log settings.
- Attach persistent volumes for
/pb/pb_data(and/pb/logsif used) sized for your database and uploads. - Deploy. Your PocketBase instance will be reachable at
https://example-app.klutch.sh; attach a custom domain if desired.
Sample API usage
Create a collection (replace admin token):
curl -X POST "https://example-app.klutch.sh/api/collections" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <admin_token>" \ -d '{"name":"notes","type":"base","schema":[{"name":"title","type":"text","required":true}]}'Create a record:
curl -X POST "https://example-app.klutch.sh/api/collections/notes/records" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <admin_token>" \ -d '{"title":"Hello from PocketBase on Klutch.sh"}'Health checks and production tips
- Add an HTTP probe to
/api/healthor/for readiness. - Enforce HTTPS at the edge; forward internally to port
8090. - Keep admin tokens and encryption keys in Klutch.sh secrets; rotate regularly.
- Monitor storage usage on
/pb/pb_data; resize before it fills. - Pin PocketBase versions and test upgrades in staging; back up data before updates.
PocketBase on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root, port 8090 configured, and data persisted, you can deliver a lightweight BaaS without extra YAML or workflow overhead.