DEV Community

konsongong
konsongong

Posted on Originally published at vpsfolio.com

Self-Host AFFiNE with Docker: A Private Notion & Miro Alternative

Measured Sandbox Benchmark

Idle RAM Startup Containers Recommended VPS
271.7 MB 87.5s 4 1 GB VPS

Per-container RAM: affine 204.8 MB · postgres 63.0 MB · redis 4.0 MB (sandbox verified 2026-11-24)

View the interactive benchmark plate and full VPS sizing comparison or compare all measured stacks on VPSFolio Benchmarks.


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 3010 inside the container. We'll bind it to 127.0.0.1:3010 on 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/.affine inside the container. We'll mount a named volume affine_data to persist this. PostgreSQL data goes into postgres_data, and Redis data into redis_data.
  • Environment variables: The official docs require AFFINE_REVISION (set to stable), AFFINE_SERVER_HOST (your domain), AFFINE_SERVER_HTTPS (true if using HTTPS), AFFINE_SERVER_PORT (3010), and DATABASE_URL (PostgreSQL connection string). Redis is configured via REDIS_SERVER_HOST and REDIS_SERVER_PORT. Secrets like DB_PASSWORD and REDIS_PASSWORD must 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
Enter fullscreen mode Exit fullscreen mode

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:
Enter fullscreen mode Exit fullscreen mode

Start the stack:

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Check logs to ensure AFFiNE connects to Postgres and Redis:

docker compose logs -f affine
Enter fullscreen mode Exit fullscreen mode

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}
    }
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 .
Enter fullscreen mode Exit fullscreen mode

Common pitfalls:

  1. WebSocket failures: If real-time collaboration doesn't work, check that your reverse proxy forwards WebSocket connections. Missing Upgrade headers cause the editor to fall back to polling, which is slower and may break.
  2. Database connection errors: Ensure the DATABASE_URL uses the correct password and that Postgres is healthy before AFFiNE starts. The depends_on with healthcheck helps, but if you change the password in .env, you must recreate the Postgres volume or update the password inside the database.
  3. File upload limits: Large file uploads may fail if your reverse proxy has a low body size limit. Set client_max_body_size in Nginx or request_body limits 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.


Originally published with full interactive benchmark metrics and server sizing notes at https://vpsfolio.com/self-host-affine-docker/.

Top comments (0)