docker.recipes

PocketBase Backend Stack

beginner

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:latest
4 ports:
5 - "8090:8090"
6 volumes:
7 - pocketbase_data:/pb_data
8 - pocketbase_public:/pb_public
9 - pocketbase_migrations:/pb_migrations
10 networks:
11 - pb-net
12 restart: unless-stopped
13
14 litestream:
15 image: litestream/litestream:latest
16 volumes:
17 - pocketbase_data:/data
18 - ./litestream.yml:/etc/litestream.yml:ro
19 command: replicate
20 depends_on:
21 - pocketbase
22 networks:
23 - pb-net
24 restart: unless-stopped
25
26 nginx:
27 image: nginx:alpine
28 ports:
29 - "80:80"
30 - "443:443"
31 volumes:
32 - ./nginx.conf:/etc/nginx/nginx.conf:ro
33 - ./certs:/etc/nginx/certs:ro
34 depends_on:
35 - pocketbase
36 networks:
37 - pb-net
38 restart: unless-stopped
39
40volumes:
41 pocketbase_data:
42 pocketbase_public:
43 pocketbase_migrations:
44
45networks:
46 pb-net:
47 driver: bridge

.env Template

.env
1# PocketBase superuser created on first run
2
3# Litestream S3 backup (optional)
4LITESTREAM_ACCESS_KEY_ID=
5LITESTREAM_SECRET_ACCESS_KEY=
6LITESTREAM_BUCKET=

Usage Notes

  1. 1PocketBase Admin at http://localhost:8090/_/
  2. 2Create admin account on first visit
  3. 3Real-time subscriptions built-in
  4. 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 file
2cat > docker-compose.yml << 'EOF'
3services:
4 pocketbase:
5 image: ghcr.io/muchobien/pocketbase:latest
6 ports:
7 - "8090:8090"
8 volumes:
9 - pocketbase_data:/pb_data
10 - pocketbase_public:/pb_public
11 - pocketbase_migrations:/pb_migrations
12 networks:
13 - pb-net
14 restart: unless-stopped
15
16 litestream:
17 image: litestream/litestream:latest
18 volumes:
19 - pocketbase_data:/data
20 - ./litestream.yml:/etc/litestream.yml:ro
21 command: replicate
22 depends_on:
23 - pocketbase
24 networks:
25 - pb-net
26 restart: unless-stopped
27
28 nginx:
29 image: nginx:alpine
30 ports:
31 - "80:80"
32 - "443:443"
33 volumes:
34 - ./nginx.conf:/etc/nginx/nginx.conf:ro
35 - ./certs:/etc/nginx/certs:ro
36 depends_on:
37 - pocketbase
38 networks:
39 - pb-net
40 restart: unless-stopped
41
42volumes:
43 pocketbase_data:
44 pocketbase_public:
45 pocketbase_migrations:
46
47networks:
48 pb-net:
49 driver: bridge
50EOF
51
52# 2. Create the .env file
53cat > .env << 'EOF'
54# PocketBase superuser created on first run
55
56# Litestream S3 backup (optional)
57LITESTREAM_ACCESS_KEY_ID=
58LITESTREAM_SECRET_ACCESS_KEY=
59LITESTREAM_BUCKET=
60EOF
61
62# 3. Start the services
63docker compose up -d
64
65# 4. View logs
66docker compose logs -f

One-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 | bash

Troubleshooting

  • 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

Ad Space