2026-11-20 · affine · docker · self-hosting · productivity
Self-Host AFFiNE with Docker: A Private Notion & Miro Alternative
Deploy AFFiNE, the open-source knowledge base, with Docker Compose. Includes Postgres, Redis, reverse proxy setup, and backup tips.
- Total RAM
- 271.7 MB
- Startup
- 87.5 s
- Port
- 3010
- HTTP
- 302
affine 204.8 MB
· postgres 63.0 MB
· redis 4.0 MB
What AFFiNE does and what it needs
AFFiNE is an open-source, local-first workspace that merges docs, whiteboards, and databases into one canvas. It’s a privacy-focused alternative to Notion and Miro, letting you write, draw, and plan in a single tool. The self-hosted Community Edition (CE) is free under the MIT license and runs entirely on your infrastructure.
Under the hood, AFFiNE uses a Node.js server, PostgreSQL for persistent storage, and Redis for caching and real-time collaboration. The official Docker image (ghcr.io/toeverything/affine) bundles the backend and frontend. You’ll need Docker and Docker Compose installed on a Linux host. The project does not publish a minimum RAM requirement; memory usage scales with active users and document complexity—idle instances can run on modest resources, while heavy collaborative editing benefits from more.
Prerequisites, ports, and volume constraints
- A Linux server (Ubuntu 22.04 or similar) with Docker Engine 24+ and Docker Compose v2.
- A domain name pointing to your server’s IP (for HTTPS via reverse proxy).
- Ports: AFFiNE listens on port
3010inside the container. We’ll bind it to127.0.0.1:3010on the host to avoid exposing it directly. You’ll also need ports 80 and 443 for the reverse proxy (Caddy or Nginx). - Volumes: AFFiNE stores uploads and configuration in
/root/.affineinside the container. We’ll mount a named volumeaffine_datato persist this. PostgreSQL data goes intopostgres_data, and Redis data intoredis_data. - Environment variables: The official docs require
AFFINE_REVISION(set tostable),AFFINE_SERVER_HOST(your domain),AFFINE_SERVER_HTTPS(true if using HTTPS),AFFINE_SERVER_PORT(3010), andDATABASE_URL(PostgreSQL connection string). Redis is configured viaREDIS_SERVER_HOSTandREDIS_SERVER_PORT. Secrets likeDB_PASSWORDandREDIS_PASSWORDmust be set in.env.
Production Docker Compose setup
Create a directory for AFFiNE and generate a .env file with strong secrets:
mkdir -p ~/affine && cd ~/affine
cat <<'EOF' > .env
# Domain and HTTPS
AFFINE_SERVER_HOST=affine.example.com
AFFINE_SERVER_HTTPS=true
# Database
DB_USER=affine
DB_PASSWORD=$(openssl rand -hex 32)
DB_NAME=affine
# Redis
REDIS_PASSWORD=$(openssl rand -hex 32)
# Timezone
TZ=UTC
EOF
Now create compose.yml:
services:
affine:
image: ghcr.io/toeverything/affine:stable
container_name: affine_server
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
affine_migration:
condition: service_completed_successfully
ports:
- "127.0.0.1:3010:3010"
environment:
REDIS_SERVER_HOST: redis
REDIS_SERVER_PORT: 6379
DATABASE_URL: postgresql://${DB_USER:-affine}:${DB_PASSWORD}@postgres:5432/${DB_NAME:-affine}
DEPLOYMENT_TYPE: selfhosted
AFFINE_SERVER_HOST: ${AFFINE_SERVER_HOST:-localhost}
AFFINE_SERVER_HTTPS: ${AFFINE_SERVER_HTTPS:-false}
AFFINE_SERVER_PORT: 3010
TZ: ${TZ:-UTC}
volumes:
- affine_storage:/root/.affine/storage
- affine_config:/root/.affine/config
affine_migration:
image: ghcr.io/toeverything/affine:stable
container_name: affine_migration_job
command: ["sh", "-c", "node ./scripts/self-host-predeploy.js"]
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
environment:
REDIS_SERVER_HOST: redis
REDIS_SERVER_PORT: 6379
DATABASE_URL: postgresql://${DB_USER:-affine}:${DB_PASSWORD}@postgres:5432/${DB_NAME:-affine}
DEPLOYMENT_TYPE: selfhosted
volumes:
- affine_storage:/root/.affine/storage
- affine_config:/root/.affine/config
postgres:
image: pgvector/pgvector:pg16
container_name: affine_postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${DB_USER:-affine}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME:-affine}
POSTGRES_INITDB_ARGS: "--data-checksums"
TZ: ${TZ:-UTC}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-affine} -d ${DB_NAME:-affine}"]
interval: 10s
timeout: 5s
retries: 10
redis:
image: redis:7-alpine
container_name: affine_redis
restart: unless-stopped
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
volumes:
affine_storage:
affine_config:
postgres_data:
redis_data:
Start the stack:
docker compose up -d
Check logs to ensure AFFiNE connects to Postgres and Redis:
docker compose logs -f affine
Reverse proxy, HTTPS, and first-run hardening
AFFiNE requires WebSocket support for real-time collaboration. Configure your reverse proxy to forward WebSocket upgrades and set appropriate headers. Below is a Caddyfile example (Caddy handles HTTPS automatically):
affine.example.com {
reverse_proxy 127.0.0.1:3010 {
header_up X-Forwarded-Proto {scheme}
header_up X-Forwarded-Host {host}
}
}
If using Nginx, ensure proxy_set_header Upgrade $http_upgrade; and proxy_set_header Connection "upgrade"; are set for WebSocket paths (typically /socket.io/). Also set client_max_body_size to at least 100M to allow large uploads.
After the stack is running, visit https://affine.example.com. The first user to sign up becomes the admin. Immediately create a strong password and enable two-factor authentication if available. Restrict sign-ups if you want a private instance—AFFiNE CE does not have a built-in toggle, so you may need to use a reverse proxy rule to block the sign-up endpoint after creating your account.
Updating, backups, and common pitfalls
To update AFFiNE, pull the latest image and recreate the container:
docker compose pull
docker compose up -d
Back up your data by dumping the PostgreSQL database and archiving the affine_data volume:
docker compose exec postgres pg_dump -U affine affine > affine_backup.sql
docker run --rm -v affine_data:/data -v $(pwd):/backup alpine tar czf /backup/affine_data_backup.tar.gz -C /data .
Common pitfalls:
- WebSocket failures: If real-time collaboration doesn’t work, check that your reverse proxy forwards WebSocket connections. Missing
Upgradeheaders cause the editor to fall back to polling, which is slower and may break. - Database connection errors: Ensure the
DATABASE_URLuses the correct password and that Postgres is healthy before AFFiNE starts. Thedepends_onwith healthcheck helps, but if you change the password in.env, you must recreate the Postgres volume or update the password inside the database. - File upload limits: Large file uploads may fail if your reverse proxy has a low body size limit. Set
client_max_body_sizein Nginx orrequest_bodylimits in Caddy accordingly.
Measured in our sandbox run: total memory 271.7 MB (sum of per-container peaks over a 30s idle window after startup) across 4 containers; largest container 204.8 MB; published port(s) 3010; HTTP probe returned 302. The run took 87.5s including the image download. Required secret(s) DB_PASSWORD were generated for the test run, as the tutorial instructs. Container breakdown: affine 204.8 MB, postgres 63.0 MB, redis 4.0 MB. Verified one-shot jobs: affine_migration (exit 0).
Verification: we ran this docker-compose stack in a disposable Docker environment and recorded the measurements above. They describe that run, not a guarantee for your host.