Deploying AFFiNE
This guide walks you through deploying AFFiNE using Docker Compose, the recommended method for self-hosting.Prerequisites
Before you begin, ensure you have:- Docker Engine 24.0 or later
- Docker Compose 2.0 or later
- At least 4 GB RAM available
- 20 GB+ free disk space
- A domain name (optional, for production)
- Basic knowledge of Docker and Linux
Docker Compose Deployment
Step 1: Prepare the Environment
Create a directory for your AFFiNE deployment:Step 2: Download Configuration Files
Download the official Docker Compose configuration:Step 3: Understanding the Docker Compose Stack
Thecompose.yml file defines the following services:
affine - Application Server
affine - Application Server
The main AFFiNE application server.
affine_migration - Database Migrations
affine_migration - Database Migrations
A one-time job that runs database migrations before the main application starts.
postgres - Database
postgres - Database
PostgreSQL 16 with pgvector extension for vector embeddings.
redis - Cache & Sessions
redis - Cache & Sessions
Redis for caching, sessions, and job queues.
Step 4: Configure Environment Variables
Edit the.env file with your configuration:
.env
Step 5: Start the Services
Launch the entire stack:Step 6: Check Logs
Monitor the application logs:Step 7: Access AFFiNE
Open your browser and navigate to:- Local:
http://localhost:3010 - Domain:
https://affine.yourdomain.com(if configured)
Production Deployment with Reverse Proxy
For production deployments, use a reverse proxy like Nginx or Caddy to handle HTTPS.Using Nginx
Using Caddy
Caddy automatically handles HTTPS:Caddyfile
Volume Persistence
The Docker Compose setup uses three persistent volumes:Database Volume
Database Volume
Path:
~/.affine/self-host/postgres/pgdataStores all PostgreSQL data including:- User accounts and workspaces
- Document content and history
- Permissions and settings
- Vector embeddings for search
Storage Volume
Storage Volume
Path:
~/.affine/self-host/storageStores uploaded files:- User avatars
- Document attachments
- Images and videos
- Binary blobs
Config Volume
Config Volume
Path:
~/.affine/self-host/configStores configuration files:config.json- Application configuration- Private keys (generated automatically)
Updating Your Deployment
To update to a new version:Troubleshooting
Container won't start
Container won't start
Check logs for errors:Common issues:
- Database not ready: Wait for
postgresto become healthy - Port already in use: Change
PORTin.env - Permission issues: Check file ownership of volume directories
Cannot connect to database
Cannot connect to database
Verify database is running and healthy:Check database credentials match in
.envWebSocket connections failing
WebSocket connections failing
Ensure your reverse proxy is configured to handle WebSocket connections. Check:
UpgradeandConnectionheaders are passed- Long timeouts are configured
- No buffering on WebSocket routes
For more troubleshooting help, visit the AFFiNE Discord or GitHub Discussions.