Trilium: Hierarchical Note-Taking
Personal knowledge base with powerful features. Tree structure, scripting, and web clipper.
Introduction
Trilium Notes is a hierarchical note-taking application with a focus on building large personal knowledge bases. It offers a rich WYSIWYG editor, powerful note organization through tree structure, note relationships, full-text search, and advanced scripting capabilities.
Why Choose Trilium Notes?
- Hierarchical Organization: Build a tree structure for your notes with unlimited depth
- Rich Text Editing: WYSIWYG editor with markdown support
- Note Relations: Create bidirectional links and relationship maps
- Scripting: Automate tasks with JavaScript
- Encryption: Protect sensitive notes with strong encryption
- Synchronization: Sync between multiple instances
- Version History: Track changes to your notes over time
- Customization: Themes, custom CSS, and extensive configuration options
Use Cases
- Personal knowledge management
- Research organization
- Project documentation
- Daily journaling with templates
- Code snippet library
- Book notes and reading lists
- Task management and GTD systems
Prerequisites
Before you begin, ensure you have:
- Docker and Docker Compose installed on your server
- Basic understanding of Docker networking
- At least 1GB of available RAM
- 5-10GB of disk space for notes and attachments
- (Optional) Domain name for reverse proxy setup
- (Optional) SSL certificate for HTTPS access
Quick Start with Docker Compose
Basic Configuration
Create a directory for Trilium and set up the Docker Compose file:
mkdir -p ~/homelab/trilium
cd ~/homelab/trilium
nano docker-compose.yml Here’s a basic Docker Compose configuration:
version: '3.8'
services:
trilium:
image: zadam/trilium:latest
container_name: trilium
restart: unless-stopped
ports:
- "8080:8080"
volumes:
- trilium-data:/home/node/trilium-data
environment:
- TRILIUM_DATA_DIR=/home/node/trilium-data
- TZ=America/New_York
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
volumes:
trilium-data:
driver: local Advanced Configuration with Reverse Proxy
For production use with Traefik or Nginx Proxy Manager:
version: '3.8'
services:
trilium:
image: zadam/trilium:latest
container_name: trilium
restart: unless-stopped
networks:
- trilium_network
- proxy
expose:
- 8080
volumes:
- trilium-data:/home/node/trilium-data
- trilium-backups:/home/node/backups
environment:
- TRILIUM_DATA_DIR=/home/node/trilium-data
- TZ=America/New_York
- NODE_ENV=production
labels:
- "traefik.enable=true"
- "traefik.http.routers.trilium.rule=Host(`notes.yourdomain.com`)"
- "traefik.http.routers.trilium.entrypoints=websecure"
- "traefik.http.routers.trilium.tls=true"
- "traefik.http.routers.trilium.tls.certresolver=letsencrypt"
- "traefik.http.services.trilium.loadbalancer.server.port=8080"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
networks:
trilium_network:
driver: bridge
proxy:
external: true
volumes:
trilium-data:
driver: local
trilium-backups:
driver: local Deploy Trilium
Start the container:
docker-compose up -d Check the logs to ensure everything is running correctly:
docker-compose logs -f trilium Initial Setup
First-Time Access
- Navigate to
http://YOUR-SERVER-IP:8080in your web browser - You’ll be prompted to create an admin password
- Choose a strong password - this will encrypt your data
- Complete the initial setup wizard
Important First Steps
After logging in for the first time:
- Configure Backup: Go to Options → Backup and set up automatic backups
- Set Theme: Options → Appearance to choose light/dark theme
- Configure Sync (if needed): Options → Sync for multi-device setup
- Create Note Templates: Set up templates for recurring note types
- Install Scripts: Browse community scripts for enhanced functionality
Data Organization
Note Types
Trilium supports various note types:
- Text Notes: Rich text with WYSIWYG editor
- Code Notes: Syntax-highlighted code with language support
- Render Notes: Custom HTML/CSS rendering
- Book Notes: Organize sub-notes as chapters
- Relation Map: Visual relationship diagrams
- Web View: Embed web content
Organizational Strategies
Create a logical structure:
Root
├── Personal
│ ├── Journal
│ ├── Health
│ └── Finance
├── Work
│ ├── Projects
│ ├── Meetings
│ └── Tasks
├── Knowledge
│ ├── Programming
│ ├── Homelab
│ └── Tutorials
└── Archive
└── Old Projects Using Attributes and Relations
Add metadata to notes:
- Labels:
#tag,#priority=high,#status=active - Relations:
~author=John,~projectLink=noteId - Template: Create note templates with
#templatelabel - CSS: Custom styling with
#cssClass=myStyle
Backup and Restore
Automated Backups
Trilium includes built-in backup functionality:
- Go to Options → Backup
- Enable automatic backups
- Set backup frequency (daily recommended)
- Configure retention policy
Manual Database Backup
Create a backup script:
#!/bin/bash
# backup-trilium.sh
BACKUP_DIR="/path/to/backups"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
CONTAINER_NAME="trilium"
# Create backup directory
mkdir -p "$BACKUP_DIR"
# Stop Trilium temporarily for consistent backup
docker-compose stop trilium
# Backup data directory
docker run --rm --volumes-from $CONTAINER_NAME -v $BACKUP_DIR:/backup alpine tar czf /backup/trilium_backup_$TIMESTAMP.tar.gz /home/node/trilium-data
# Restart Trilium
docker-compose start trilium
# Keep only last 30 days of backups
find $BACKUP_DIR -name "trilium_backup_*.tar.gz" -mtime +30 -delete
echo "Backup completed: trilium_backup_$TIMESTAMP.tar.gz" Make it executable and add to crontab:
chmod +x backup-trilium.sh
crontab -e
# Add: 0 2 * * * /path/to/backup-trilium.sh Restore from Backup
To restore a backup:
# Stop Trilium
docker-compose down
# Extract backup
docker run --rm -v trilium-data:/home/node/trilium-data -v /path/to/backups:/backup alpine tar xzf /backup/trilium_backup_TIMESTAMP.tar.gz -C /
# Restart Trilium
docker-compose up -d Data Import and Export
Import from Other Apps
Trilium supports importing from:
- Markdown files: Drag and drop .md files
- HTML files: Import from web clippers
- OPML files: From outliner applications
- CSV: Structured data import
Export Options
Export your notes:
- Single Note: Right-click → Export → Choose format
- Subtree: Export entire note hierarchies
- Full Database: Options → Advanced → Export full database
- HTML Export: For sharing or archiving
- Markdown Export: For portability
Bulk Import Script
Import multiple markdown files:
#!/bin/bash
# import-markdown.sh
SOURCE_DIR="/path/to/markdown/files"
TRILIUM_URL="http://localhost:8080"
TOKEN="YOUR_API_TOKEN"
for file in "$SOURCE_DIR"/*.md; do
filename=$(basename "$file" .md)
content=$(cat "$file")
curl -X POST "$TRILIUM_URL/api/create-note" -H "Authorization: $TOKEN" -H "Content-Type: application/json" -d "{
"parentNoteId": "root",
"title": "$filename",
"type": "text",
"content": $(echo "$content" | jq -Rs .)
}"
done Synchronization
Server-Server Sync
Set up sync between multiple Trilium instances:
On Server Instance:
- Go to Options → Sync
- Enable sync server
- Note the sync URL and generate sync password
On Client Instance:
- Options → Sync
- Enter server URL and sync password
- Click “Test Connection”
- Enable sync
Sync Configuration
Edit the sync settings in docker-compose.yml:
environment:
- TRILIUM_DATA_DIR=/home/node/trilium-data
- TRILIUM_SYNC_SERVER_HOST=0.0.0.0
- TRILIUM_SYNC_SERVER_PORT=8080 Advanced Features
Custom Scripts
Create automated workflows:
// Example: Auto-tag notes based on content
async function autoTag() {
const notes = await api.searchForNotes('note.text*=*homelab*');
for (const note of notes) {
await note.setLabel('category', 'homelab');
}
} API Usage
Trilium provides a REST API:
# Get note content
curl -H "Authorization: YOUR_TOKEN" http://localhost:8080/api/notes/NOTE_ID/content
# Create new note
curl -X POST http://localhost:8080/api/notes -H "Authorization: YOUR_TOKEN" -H "Content-Type: application/json" -d '{"title": "My Note", "content": "Note content"}' Encryption
Protect sensitive notes:
- Select note to encrypt
- Right-click → Note actions → Protect note
- Enter encryption password
- Password is required to view/edit
Authentication and Security
Password Management
- Change Password: Options → Change Password
- Password Requirements: Minimum 8 characters recommended
- Password Recovery: Not possible - keep secure backup
- Protected Notes: Additional encryption layer
Security Best Practices
- Use Strong Password: 16+ characters with complexity
- Enable HTTPS: Always use SSL in production
- Regular Backups: Encrypted backup storage
- Access Control: Use reverse proxy for IP filtering
- Update Regularly: Keep Docker image updated
- Protected Sessions: Configure session timeout
Network Security
Restrict access with firewall rules:
# Allow only local network
sudo ufw allow from 192.168.1.0/24 to any port 8080
# Or use reverse proxy
sudo ufw deny 8080 Troubleshooting
Common Issues
Trilium won’t start
# Check logs
docker-compose logs trilium
# Common causes:
# 1. Port 8080 already in use
docker ps | grep 8080
# 2. Permission issues
sudo chown -R 1000:1000 trilium-data/
# 3. Corrupted database
# Restore from backup Slow Performance
# Check resource usage
docker stats trilium
# Increase memory limit in docker-compose.yml
deploy:
resources:
limits:
memory: 2G
reservations:
memory: 1G Sync Issues
- Verify network connectivity between instances
- Check sync password is correct
- Ensure both instances are on same version
- Review sync logs in Options → Advanced → Show Sync Log
Database Corruption
# Run database integrity check
docker exec -it trilium node src/check-integrity.js
# If corrupted, restore from backup
docker-compose down
# Restore backup process (see Backup section)
docker-compose up -d Reset Admin Password
If you forget your password:
# This will reset the database - backup first!
docker-compose down
docker volume rm trilium_trilium-data
docker-compose up -d
# You'll go through initial setup again Enable Debug Logging
For troubleshooting:
environment:
- DEBUG=*
- NODE_ENV=development Maintenance
Regular Updates
Update Trilium to the latest version:
# Pull latest image
docker-compose pull trilium
# Recreate container
docker-compose up -d trilium
# Verify version
docker exec trilium node --version Database Optimization
Periodic maintenance:
# Vacuum database (reduces size)
docker exec -it trilium sqlite3 /home/node/trilium-data/document.db "VACUUM;"
# Check database size
docker exec trilium du -h /home/node/trilium-data/document.db Monitoring
Monitor Trilium health:
# Check container health
docker inspect trilium | grep -A 10 Health
# Monitor logs for errors
docker-compose logs -f --tail=100 trilium
# Resource monitoring
docker stats trilium --no-stream Tips and Best Practices
Organizational Tips
- Use Templates: Create templates for recurring note types
- Consistent Naming: Develop naming conventions
- Tag Strategically: Don’t over-tag, keep it meaningful
- Regular Reviews: Weekly review and reorganization
- Archive Old Notes: Keep tree structure manageable
Performance Optimization
- Image Optimization: Compress images before adding
- Regular Vacuum: Monthly database optimization
- Limit Tree Depth: Avoid excessive nesting
- Archive Old Data: Move inactive notes to archive
Workflow Integration
- Web Clipper: Use browser extension for web content
- Mobile Access: Access via mobile browser
- API Integration: Automate with scripts
- Backup Automation: Set it and forget it
Additional Resources
- Official Documentation: https://github.com/zadam/trilium/wiki
- Community Forum: https://github.com/zadam/trilium/discussions
- Docker Hub: https://hub.docker.com/r/zadam/trilium
- Script Repository: Browse community scripts in the wiki
- Themes: Custom CSS themes in documentation
Conclusion
Trilium Notes is a powerful, flexible note-taking system perfect for building comprehensive personal knowledge bases. With proper setup, regular backups, and good organizational habits, it becomes an invaluable tool for managing information.
The self-hosted nature ensures your data privacy while the rich feature set provides everything needed for advanced knowledge management. Start simple, explore features gradually, and customize Trilium to fit your workflow.
Happy note-taking!