PocketBase Backend Stack
Open source backend in a single file with real-time database and auth.
Overview
PocketBase is a revolutionary open-source backend-as-a-service that packages a complete backend solution into a single executable file, featuring SQLite as its database engine with built-in real-time subscriptions, authentication, file storage, and an admin dashboard. Developed as a Firebase alternative, PocketBase eliminates the complexity of traditional backend architectures by providing REST and real-time APIs, user management, and database administration out of the box, making it perfect for rapid prototyping and production deployments alike.
This stack combines PocketBase with NGINX as a reverse proxy for enhanced security and SSL termination, while Litestream provides automated SQLite database replication to cloud storage services like S3, ensuring data durability and backup capabilities. The combination addresses PocketBase's single-file nature by adding enterprise-grade features like load balancing, caching, and continuous database backup without sacrificing simplicity.
This configuration is ideal for developers building modern web applications, mobile app backends, or SaaS platforms who need a complete backend solution without the overhead of managing multiple services, databases, and authentication systems. Startups and solo developers particularly benefit from this stack's minimal operational complexity while maintaining scalability and data protection through automated backups.
Key Features
- Built-in real-time database subscriptions with automatic WebSocket connections for live data updates
- Complete authentication system with OAuth2, email/password, and custom auth providers
- Admin dashboard at /_/ route for database management, user administration, and API rule configuration
- Automatic SQLite WAL mode replication to S3, Google Cloud, or Azure via Litestream
- NGINX reverse proxy with SSL termination and static file serving optimization
- Schema migrations system with JavaScript hooks for custom business logic
- File storage with automatic image resizing and thumbnail generation
- RESTful APIs with real-time filtering, sorting, and pagination built-in
Common Use Cases
- 1Rapid MVP development for SaaS applications requiring user authentication and real-time features
- 2Mobile app backends needing offline-first capabilities with real-time sync
- 3Small to medium e-commerce platforms with inventory management and order processing
- 4Content management systems with multi-user collaboration and live editing
- 5IoT dashboards collecting sensor data with real-time monitoring and alerting
- 6Educational platforms with student progress tracking and live classroom features
- 7Team collaboration tools requiring real-time updates and file sharing capabilities
Prerequisites
- Docker and Docker Compose installed with at least 512MB available RAM
- Port 80 and 443 available for NGINX, port 8090 for PocketBase admin access
- Valid SSL certificates placed in ./certs directory for HTTPS configuration
- Litestream configuration file (litestream.yml) with cloud storage credentials
- NGINX configuration file (nginx.conf) with PocketBase upstream server settings
- Basic understanding of SQLite database concepts and REST API principles
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 pocketbase: 3 image: ghcr.io/muchobien/pocketbase:latest4 ports: 5 - "8090:8090"6 volumes: 7 - pocketbase_data:/pb_data8 - pocketbase_public:/pb_public9 - pocketbase_migrations:/pb_migrations10 networks: 11 - pb-net12 restart: unless-stopped1314 litestream: 15 image: litestream/litestream:latest16 volumes: 17 - pocketbase_data:/data18 - ./litestream.yml:/etc/litestream.yml:ro19 command: replicate20 depends_on: 21 - pocketbase22 networks: 23 - pb-net24 restart: unless-stopped2526 nginx: 27 image: nginx:alpine28 ports: 29 - "80:80"30 - "443:443"31 volumes: 32 - ./nginx.conf:/etc/nginx/nginx.conf:ro33 - ./certs:/etc/nginx/certs:ro34 depends_on: 35 - pocketbase36 networks: 37 - pb-net38 restart: unless-stopped3940volumes: 41 pocketbase_data: 42 pocketbase_public: 43 pocketbase_migrations: 4445networks: 46 pb-net: 47 driver: bridge.env Template
.env
1# PocketBase superuser created on first run23# Litestream S3 backup (optional)4LITESTREAM_ACCESS_KEY_ID=5LITESTREAM_SECRET_ACCESS_KEY=6LITESTREAM_BUCKET=Usage Notes
- 1PocketBase Admin at http://localhost:8090/_/
- 2Create admin account on first visit
- 3Real-time subscriptions built-in
- 4Litestream for SQLite backups to S3
Individual Services(3 services)
Copy individual services to mix and match with your existing compose files.
pocketbase
pocketbase:
image: ghcr.io/muchobien/pocketbase:latest
ports:
- "8090:8090"
volumes:
- pocketbase_data:/pb_data
- pocketbase_public:/pb_public
- pocketbase_migrations:/pb_migrations
networks:
- pb-net
restart: unless-stopped
litestream
litestream:
image: litestream/litestream:latest
volumes:
- pocketbase_data:/data
- ./litestream.yml:/etc/litestream.yml:ro
command: replicate
depends_on:
- pocketbase
networks:
- pb-net
restart: unless-stopped
nginx
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./certs:/etc/nginx/certs:ro
depends_on:
- pocketbase
networks:
- pb-net
restart: unless-stopped
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 pocketbase:5 image: ghcr.io/muchobien/pocketbase:latest6 ports:7 - "8090:8090"8 volumes:9 - pocketbase_data:/pb_data10 - pocketbase_public:/pb_public11 - pocketbase_migrations:/pb_migrations12 networks:13 - pb-net14 restart: unless-stopped1516 litestream:17 image: litestream/litestream:latest18 volumes:19 - pocketbase_data:/data20 - ./litestream.yml:/etc/litestream.yml:ro21 command: replicate22 depends_on:23 - pocketbase24 networks:25 - pb-net26 restart: unless-stopped2728 nginx:29 image: nginx:alpine30 ports:31 - "80:80"32 - "443:443"33 volumes:34 - ./nginx.conf:/etc/nginx/nginx.conf:ro35 - ./certs:/etc/nginx/certs:ro36 depends_on:37 - pocketbase38 networks:39 - pb-net40 restart: unless-stopped4142volumes:43 pocketbase_data:44 pocketbase_public:45 pocketbase_migrations:4647networks:48 pb-net:49 driver: bridge50EOF5152# 2. Create the .env file53cat > .env << 'EOF'54# PocketBase superuser created on first run5556# Litestream S3 backup (optional)57LITESTREAM_ACCESS_KEY_ID=58LITESTREAM_SECRET_ACCESS_KEY=59LITESTREAM_BUCKET=60EOF6162# 3. Start the services63docker compose up -d6465# 4. View logs66docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/pocketbase-stack/run | bashTroubleshooting
- PocketBase admin shows 'failed to create admin': Delete the pb_data volume and restart to reset the admin account creation
- Litestream 'authentication failed' error: Verify cloud storage credentials in litestream.yml and ensure proper IAM permissions
- NGINX 502 Bad Gateway: Check if PocketBase is running on port 8090 and accessible within the pb-net Docker network
- Real-time subscriptions not working: Ensure NGINX configuration includes WebSocket upgrade headers for PocketBase connections
- SQLite database locked errors: Stop all containers, verify no orphaned PocketBase processes, then restart the stack
- SSL certificate errors: Verify certificate files exist in ./certs directory and match the domain names in nginx.conf
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
pocketbasenginxlitestream
Tags
#pocketbase#backend#sqlite#realtime#auth
Category
Full Web StacksAd Space
Shortcuts: C CopyF FavoriteD Download