Deployn

Install AFFiNE with Docker Compose and Caddy

Self-host AFFiNE with Docker Compose. See how to use documents, the Edgeless whiteboard, Kanban, journals and sharing, with screenshots and backup steps.

Install AFFiNE with Docker Compose and Caddy hero image
Contents
Tested with
AFFiNE 0.27.4Debian 13Docker 29.10.1Docker Compose 5.8.0Caddy 2.6.2PostgreSQL 16.16Valkey 9.2.1
Last checked on

For a bike repair day, I would usually write up the schedule, keep a task list somewhere and sketch the setup on a whiteboard. In AFFiNE, I can write the schedule, switch that same page to the whiteboard and link to the task board from there.

I install AFFiNE with Docker Compose and Caddy on a Debian server. For the examples, I create a workspace for a fictional bike repair shop. It holds Saturday’s schedule, three prep tasks and a journal entry about getting into the courtyard.

Summary
  • Document and whiteboard. Every page has a text view and a freeform canvas called Edgeless. I can put the text next to shapes and arrows on the canvas.
  • Tasks and notes. A database can show the same records as a table, a Kanban board or a calendar. Page links, tags, collections and the journal help me find the related notes.
  • Your own server. Docker Compose runs AFFiNE, PostgreSQL and Valkey. Caddy handles HTTPS. The backup covers the database, attachments and configuration.

Install AFFiNE with Docker Compose

Server with a sudo userI use Debian 13 on a Hetzner VPS with 2 vCPUs and 4 GB of RAM. I set up SSH access as described in my VPS guide.
Domain and HTTPSThe A record for {{domain}} points to your server. Caddy needs TCP ports 80 and 443 reachable. I only add an AAAA record when IPv6 works on the server.
Disk spaceLeave room for the container images, PostgreSQL and any images, PDFs or other files you attach. The AFFiNE system requirements recommend at least four CPU cores.
  1. Install Docker and Caddy

    Connect to your server over SSH with your own user account. I use deployn and run Docker with sudo. If you already have Docker Compose, install the caddy package. Docker package repository for Debian

    Terminalbash
    sudo apt update
    sudo apt install -y ca-certificates curl openssl caddy
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc
    
    . /etc/os-release
    sudo tee /etc/apt/sources.list.d/docker.sources >/dev/null <<EOF
    Types: deb
    URIs: https://download.docker.com/linux/debian
    Suites: $VERSION_CODENAME
    Components: stable
    Architectures: $(dpkg --print-architecture)
    Signed-By: /etc/apt/keyrings/docker.asc
    EOF
    
    sudo apt update
    sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    sudo docker compose version
  2. Create the project directory and database password

    Terminalbash
    mkdir -p ~/affine/config
    cd ~/affine
    (umask 077; printf 'POSTGRES_PASSWORD=%s\n' "$(openssl rand -hex 32)" > .env)
    .envdotenv
    POSTGRES_PASSWORD=DEIN_ERZEUGTES_HEX_PASSWORT

    The command writes the password to the file for you. Run it once when setting up a new instance. PostgreSQL takes the password from .env when it first starts with an empty data directory. I use hexadecimal characters because the password is also part of the PostgreSQL URL. If you choose your own password, characters such as @ need URL encoding there.

  3. Create the Compose file and AFFiNE configuration

    Save the file as ~/affine/compose.yaml. I use AFFiNE 0.27.4, a password-protected database and Valkey as a Redis-compatible service. The YAML anchor &affine gives the server and migration job the same image and settings.

    compose.yamlyaml
    name: affine
    
    x-affine: &affine
        image: ghcr.io/toeverything/affine:0.27.4
        environment:
            DATABASE_URL: postgresql://affine:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD fehlt}@postgres:5432/affine
            REDIS_SERVER_HOST: valkey
            AFFINE_INDEXER_ENABLED: "false"
        volumes:
            - ./data/storage:/root/.affine/storage
            - ./config:/root/.affine/config
    
    services:
        affine:
            <<: *affine
            ports:
                - "127.0.0.1:3010:3010"
            depends_on:
                migration:
                    condition: service_completed_successfully
            restart: unless-stopped
    
        migration:
            <<: *affine
            command: ["sh", "-c", "node ./scripts/self-host-predeploy.js"]
            depends_on:
                postgres:
                    condition: service_healthy
                valkey:
                    condition: service_healthy
    
        postgres:
            image: pgvector/pgvector:pg16
            environment:
                POSTGRES_DB: affine
                POSTGRES_USER: affine
                POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD fehlt}
                POSTGRES_INITDB_ARGS: --data-checksums
            volumes:
                - ./data/postgres:/var/lib/postgresql/data
            healthcheck:
                test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "affine", "-d", "affine"]
                interval: 5s
                timeout: 5s
                retries: 10
            restart: unless-stopped
    
        valkey:
            image: valkey/valkey:9
            healthcheck:
                test: ["CMD", "valkey-cli", "ping"]
                interval: 5s
                timeout: 5s
                retries: 10
            restart: unless-stopped
    • Migration prepares the database and reports Exited (0) when it finishes successfully.
    • PostgreSQL stores accounts, workspaces and documents. The image includes the pgvector extension.
    • Valkey fills the role of Redis in this setup. Both PostgreSQL and Valkey stay on the private Compose network.
    • AFFiNE is reachable on port 3010 from the server itself, where Caddy can connect to it. I leave the optional server indexer disabled, as in the release example.

    Create ~/affine/config/config.json with the public address you plan to use. AFFiNE uses it when generating links for other people to open. AFFiNE configuration

    config/config.jsonjson
    {
        "server": {
            "name": "AFFiNE Self-hosted",
            "externalUrl": "https://{{domain}}"
        }
    }
    Terminalbash
    sudo docker compose config -q
    sudo docker compose up -d
    sudo docker compose ps -a

    postgres and valkey should show as healthy, with affine listed as Up. If startup stalls, I first run sudo docker compose logs migration to see whether the migration could reach the database.

  4. Set up the first admin account

    Run the command on your computer, then open http://localhost:3010/admin in your browser. If port 3010 is already in use on your computer, change the first port number in the command and use the same port in the browser.

    Terminalbash
    ssh -N -L 3010:127.0.0.1:3010 deployn@{{domain}}

    Click Continue and enter a name, email address and password. You can use the same account to sign in to AFFiNE. Once setup is complete, Accounts lists the users. I could finish this step without setting up email delivery. AFFiNE first-run setup

    AFFiNE setup wizard before creating the first administrator account

  5. Put AFFiNE behind HTTPS

    Add this block to /etc/caddy/Caddyfile. If Caddy already serves other sites, append the block to the file. Caddy and AFFiNE run on the same host here. My guide to Caddy and reverse proxies

    /etc/caddy/Caddyfilecaddy
    {{domain}} {
        reverse_proxy 127.0.0.1:3010
    }
    Terminalbash
    sudo caddy validate --config /etc/caddy/Caddyfile
    sudo systemctl reload caddy
    curl -fsS -o /dev/null -w '%{http_code}\n' https://{{domain}}/admin

    Open https://{{domain}}/admin and sign in. The main address, https://{{domain}}, opens the app. Caddy also proxies the WebSocket connections that AFFiNE uses to sync.

    AFFiNE admin panel showing user accounts and the server version

Create a workspace on your own server

When I first opened AFFiNE, I saw Demo Workspace in the top left. AFFiNE creates it in the browser, where any changes to it stay local. I open the workspace menu in the top left and click Create workspace. I enter Fahrradwerkstatt, German for “bike repair shop,” and select my AFFiNE Self-hosted server under Workspace type. This is where I create the pages I want to sync between browsers.

Workspace creation dialog for Fahrradwerkstatt with AFFiNE Self-hosted selected

You can create multiple workspaces and switch between them from the menu in the top left. The desktop app also lets you add a server from its workspace picker. Enter the public HTTPS address and sign in to your instance. The browser and desktop app can then open the same workspace on your server. Clients from version 0.27 require a server on version 0.27 or later. Servers from version 0.27 require a client on version 0.26 or later. AFFiNE desktop app

I click the + next to Search to create Fahrradwerkstatt am Samstag (“Saturday bike repair”). In the text view, I write the schedule with two headings, a list of times and a quote for the open question about rain. Each paragraph and list item is a block. Drag the handle on the left of a block to move it. If I put a time in the wrong place, that is quicker than cutting and pasting.

Text view with the bike repair schedule, open questions and a link to the task list

Type / on a line to open the block menu. It offers headings, code blocks, checklists, collapsible lists, callouts, simple tables and databases. Content & Media has images, attachments and PDFs, as well as embeds for services such as YouTube, Figma and GitHub. For two things I need to check off on the day, I use a To-do List. For tasks I want to organize by status, I use a database block. AFFiNE block reference

Editor slash menu with formatting, lists, page links and media blocks

Type @ and the name of an existing document to insert an internal link. From the schedule, I type @Aufgaben and select Aufgaben zur Eröffnung (“Opening day tasks”). At the bottom of that page, Bi-Directional Links shows the pages that link to it. I can use it to get back to the schedule from the task board. The same menu also lets me link to a date when I want to reference a daily note.

Use the same page as a whiteboard

There are two icons to the left of the page title. I click the second to switch to Edgeless. The page text appears on a card. To its right, I draw the route a bike takes through the workshop.

  1. From the bottom toolbar, I open the shapes menu, pick a rounded rectangle and drag on the canvas to draw it.
  2. I double-click each of the three shapes and label them Annahme (Drop-off), Reparatur (Repair) and Abholung (Pickup). I pick the colors in the shapes menu.
  3. With the connector tool in the toolbar, I draw an arrow from drop-off to repair and another from repair to pickup.

Edgeless view with the schedule on a text card and three connected bike repair stations

Switch back to the text view to read the schedule or export it as Markdown. The shapes you placed stay on the canvas. Note blocks can appear in both views. If you have several notes, you can adjust their reading order for the text view. AFFiNE documentation on its two page modes

The canvas also has tools for drawing, text, mind maps and Frames. I use a frame to group part of the canvas, such as a floor plan with several stations. Multiple frames can serve as slides. When I only need a space to draw together, a standalone Excaliself whiteboard usually covers it. In AFFiNE I can write up the discussion alongside the layout and link it to the tasks.

Show tasks as a Kanban board, table or calendar

On the Aufgaben zur Eröffnung page, I type /kanban and choose Kanban View. AFFiNE creates a database with columns for each status. Cards without a status go under No Status. I name the cards Ersatzteile sortieren (Sort spare parts), Werkzeug prüfen (Check the tools) and Aushang drucken (Print the notice). Then I drag them into the relevant columns. To add a task, I click New Record.

Kanban board with tasks for spare parts, tools and printing the notice

I click the + next to the view tab to add Table View. My tasks now appear as rows and keep their statuses. Change a status in the table and the same card moves on the Kanban board. I can add more properties to the table, such as a date or a checkbox. The database block also has filters and sorting. For scheduled tasks, I add Calendar View and choose a date field for it.

Table view of the same AFFiNE database showing the tasks and their statuses

The slash menu also has Table. I use a simple table to list three sizes of inner tubes and their prices. It has no Kanban or calendar view, and it is quicker to set up when I just need a few rows.

Find pages and keep a journal

On the schedule page, I click Info and add Werkstatttag (“workshop day”) under Tags. I can also click the star at the top to add the schedule to Favorites. Under Organize, I can create folders for pages. In All docs, the document list sits alongside Tags and Collections.

Document properties for the schedule showing the Werkstatttag tag

A collection can hold pages I add by hand or pick them up using rules. To create a collection called Werkstatttag, I go to All docs → Collections → New collection. With Add docs, I pick pages one at a time. With Add rules → Add Filter Rule → Tags, I can add them automatically by tag. The schedule can live in an Events folder and show up in the collection at the same time. To look up a title, I open Search in the sidebar. AFFiNE collections documentation

Under Journals, I pick the date and click Create Daily Journal. I note what time the courtyard opens and how many bike repair stands have been promised. I can use @ on the schedule page to jump to the date. Template is where I manage reusable page layouts. AFFiNE can use different templates for new documents and journal entries. AFFiNE template documentation

Journal with the week selector and a daily note about the courtyard and repair stands

Share pages and edit together

Use Invite members to invite people to the workspace. For a single schedule, open Share in the document itself. General access shows separate permissions for workspace members and people with the link. Give editing access to anyone who needs to maintain the tasks. For a public notice, AFFiNE offers Read only under Anyone with the link. On my 0.27.4 instance, the setting reverted to No access. The server reported that the feature was temporarily unavailable. I could still export the schedule as a file. AFFiNE guide to publishing a page

Share menu showing separate access settings for workspace members and people with the link

For an ongoing team workspace, I also set up SMTP. AFFiNE uses it to email invitations, for example. I can manage user accounts under Accounts in the admin panel. Server accounts and workspace memberships have separate settings. Email configuration · User management

Export pages and import files

Under Share → Export, I find HTML, PNG, Markdown, Snapshot and Print. I downloaded the schedule as Markdown. The file includes the headings, list and text, along with the labels from the three rectangles. It loses the layout and arrows. To keep the diagram, I would export an image from Edgeless. A snapshot is for content I plan to open again in AFFiNE.

Export menu with HTML, PNG, Markdown, Snapshot and Print

To import a file, I open Import in the sidebar. I could bring the exported .md file back in as a new document. The menu also offers HTML, DOCX and AFFiNE snapshots. In this version, the Notion, Obsidian and Bear importers are labeled Experimental. Before moving a whole workspace, I would import a typical page with an attachment, an internal link and a table, then check how it looks in AFFiNE. AFFiNE documentation on file formats and their limits

Import dialog with Markdown, HTML, DOCX and experimental importers for Notion and Obsidian

Limits I ran into with self-hosting

Topic What it means in practice
Team licensing and quotas AFFiNE lists up to ten seats in the basic quota for self-hosted workspaces. Adding more seats to the same workspace requires a team license. The documentation also lists current restrictions on attachments. Basic quota · Team license
AI setup The core features work without an AI key. For server-side AI, AFFiNE documents BYOK, or bringing your own provider key. If you use an external provider, the content processed for that request goes to that service. I left the provider unconfigured for this setup. AFFiNE AI documentation
Browser storage and sync A local workspace is tied to the browser profile where you created it. If you clear browser storage or change devices, you need a copy or a workspace on your server. For important changes, I wait for them to sync and check them on another client.
Language My web app showed English menu labels even with the browser set to German. I use the labels I saw in the interface.
Export and migration Markdown works for text and PNG captures a view. Individual page exports leave out parts of a full backup, including server configuration, accounts and permissions.

Back up and update AFFiNE

~/affine/Folders
  • compose.yamlServices and image tagsback up
  • .envPostgreSQL password, keep privateback up
  • config/AFFiNE configurationback up
  • data/Instance data
  • postgres/Back up with pg_dump
  • storage/Uploaded filesback up

For a consistent backup, I stop the AFFiNE container while I back up PostgreSQL and the attachment directory. The database keeps running during the backup. I then store a copy in a second location. When Caddy runs as a system service, as it does here, I include its Caddyfile.

Terminalbash
(
    set -e
    cd ~/affine
    umask 077
    backup="$HOME/affine-backup-$(date +%F-%H%M%S)"
    mkdir -m 700 "$backup"
    sudo docker compose stop affine
    trap 'sudo docker compose start affine' EXIT
    sudo docker compose exec -T postgres pg_dump -U affine -d affine -Fc > "$backup/affine.dump"
    sudo tar -czf - compose.yaml .env config data/storage > "$backup/dateien.tar.gz"
    sudo cat /etc/caddy/Caddyfile > "$backup/Caddyfile"
    sudo docker compose start affine
    trap - EXIT
)

Try restoring into a fresh stack. You need the files from the archive and the database dump. Check that you can sign in, open documents and access an attachment. Official backup and restore guide

Before updating, I read the notes for the target release and change the AFFiNE tag on the YAML anchor in compose.yaml. That keeps the app and migration job on the same version. Then I pull the images, stop the old app and start the stack with the new version. Changing the PostgreSQL major tag pg16 is a separate database upgrade. AFFiNE upgrade guide

Terminalbash
cd ~/affine
sudo docker compose pull
sudo docker compose stop affine
sudo docker compose up -d
sudo docker compose ps -a
sudo docker compose logs --tail=100 migration affine

After the update, I open the workspace, edit a note and upload a small attachment. This catches write and sync problems even when the home page loads.

Where I would use AFFiNE

I would use AFFiNE for the bike repair day because the schedule, layout and tasks are close together. I can sketch the layout and write up the meeting later on the same page. For a handbook organized into books and chapters, I would look at BookStack. If you are getting started with AFFiNE, a schedule, a linked task page and the journal make a good first workspace. You will soon see how often you reach for the canvas.

Frequently asked questions

Frequently asked questions

Can I try AFFiNE without an account?

You can open the local demo workspace in your browser. To use a workspace that syncs through your instance, sign in with an account on your server.

Do I need to forward port 3010 on my router?

In this setup, AFFiNE listens on 127.0.0.1:3010. Caddy serves it over HTTPS on port 443. Port 80 is reachable for automatic certificate issuance and redirects to HTTPS.

Do I keep my tasks when switching from Kanban to the table?

Yes. Kanban and the table show the same records in a database. Changing a status in one view updates it in the other.