
PocketBase is an open-source backend solution built with Go that bundles a real-time SQLite database, authentication system, file uploads, and administrative dashboard into a single binary. The embedded SQLite engine eliminates external database dependencies, while the built-in REST API and live subscriptions enable rapid development of web and mobile applications.
This article walks through deploying PocketBase on a Linux server with Docker Compose. The setup includes Traefik for automated TLS certificates, pre-configured admin credentials via environment variables, and a practical demonstration of collection creation and API interaction.
Before you begin, you need to:
pocketbase.example.com).PocketBase persists all data, including the SQLite database, uploaded files, and logs, in a dedicated data directory. Environment variables define the domain configuration, TLS settings, and initial administrator credentials.
Create the project folder and data directory.
pb_data: Stores the SQLite database, uploaded files, and application logs.Switch to the project folder.
Create an environment file to store configuration values.
Add the following environment variables:
Replace:
pocketbase.example.com with your registered domain.admin@example.com with your email address for certificate notifications and admin login.SecurePassword123 with a strong password. Keep the quotes if using special characters.Save and close the file.
The deployment stack consists of Traefik for reverse proxy and certificate management, plus the PocketBase container with pre-configured superuser credentials. This configuration uses the community-maintained PocketBase Docker image. On first startup, PocketBase automatically creates the admin account using the provided environment variables.
Create the Docker Compose file.
Add the following manifest:
Save and close the file.
In the above manifest:
80 and 443 on the host for external traffic handling..env file to auto-create the admin account on first startup.8090 accessible to other containers (Traefik) without binding it to the host.letsencrypt named volume stores TLS certificates persistently across container rebuilds./var/run/docker.sock) grants Traefik the ability to discover services and update routes dynamically.pb_data bind mount preserves the SQLite database, uploaded files, and application logs.The admin account is created only during the first startup when the pb_data directory is empty. If you already have an existing database and want to reinitialize the admin account, remove the data directory before starting the container:
This command permanently deletes all stored data in the pb_data directory.
Launch the containers.
Verify both services are operational.
Output:
Check the service logs for any errors.
For more information on managing a Docker Compose stack, see the How To Use Docker Compose article.
The administrative dashboard is accessible at the /_/ path. With superuser credentials configured via environment variables, the initial setup wizard is bypassed and you can log in directly.
Open your web browser and navigate to the PocketBase admin panel at https://pocketbase.example.com/_/, replacing pocketbase.example.com with your domain.
Sign in using the PB_ADMIN_EMAIL and PB_ADMIN_PASSWORD credentials from your .env file.
The dashboard provides access to:
Collections represent database tables with auto-generated REST endpoints. PocketBase provides built-in support for CRUD operations, query filters, and result pagination without additional configuration.
From the dashboard sidebar, click + New collection.
Enter tasks as the collection name. Under Fields, click + New field and add:
title, Type: Plain textcompleted, Type: BoolSwitch to the API Rules tab and configure public read access:
@request.auth.id != "" (requires authentication).@request.auth.id != "".@request.auth.id != "".Click Save changes to save the collection.
Add a sample record. Click the tasks collection, then click + New record. Fill in:
title: Learn PocketBase APIcompleted: UncheckedClick Create to save the record.
Query the collection through the REST API. Replace pocketbase.example.com with your domain:
Output:
The response contains the task record within the items array.
Test filtering records by adding query parameters:
Output:
PocketBase supports filtering, sorting, and pagination through query parameters, enabling flexible data retrieval for frontend applications.
You have successfully deployed PocketBase with HTTPS access through Traefik using Docker Compose. The configuration provides a complete backend platform with user authentication, real-time database capabilities, and file storage. PocketBase's admin interface simplifies collection management and user administration, while its REST API enables rapid application development. The SQLite-based architecture simplifies backups by allowing you to copy the pb_data directory. The single-binary design minimizes resource usage for small to medium-scale applications. For more information, refer to the official PocketBase documentation.
0 Comments
Be the first to comment and share your perspective with the community.