This guide covers production deployment of flatnotes with subdirectory support using Docker Compose.
- Docker and Docker Compose installed
- Git client
- Sufficient disk space for notes and index
1a. Copy the docker-compose.yaml and .env
OR
1b. Clone the repository:
git clone https://github.com/TheTechRun/flatnotes-ttr.git
cd flatnotes-ttr-
Configure environment:
cp .env.example .env # Edit .env with your settings -
Start the application:
docker-compose up -d
Create a .env file from the provided example:
# Flatnotes Authentication Configuration
FLATNOTES_AUTH_TYPE=password
FLATNOTES_USERNAME=your_username
FLATNOTES_PASSWORD=your_secure_password
FLATNOTES_SECRET_KEY=your_secret_key_hereSecurity Notes:
- Change default username and password
- Use a strong, unique secret key
- Keep
.envfile secure and never commit to version control
File: docker-compose.yaml
services:
flatnotes:
container_name: flatnotes-ttr
build:
context: https://github.com/TheTechRun/flatnotes-ttr.git#develop
dockerfile: Dockerfile.fork
env_file:
- .env
environment:
PUID: 5000 # change this to yours
PGID: 5000 # change this to yours
FLATNOTES_PATH: "/data"
FLATNOTES_PORT: 8080
volumes:
- "./notes:/data"
- "./index:/data/.flatnotes"
ports:
- "8053:8080"
restart: unless-stoppedConfiguration Details:
- Build Context: Builds from
developbranch on GitHub - Container Name:
flatnotes-ttr - Host Port:
8053(change if needed) - Data Volume:
./notes- stores your markdown files - Index Volume:
./index- stores search database - Restart Policy:
unless-stoppedfor automatic recovery
After first run, you'll see this structure:
flatnotes-ttr/
├── notes/ # Your actual notes
│ ├── Linux/
│ │ └── how-to-get-docker.md
│ ├── Development/
│ │ └── python/
│ │ └── virtualenv-guide.md
│ └── standalone-note.md
└── index/ # Search index database
└── .flatnotes/
├── _MAIN_0.toc
├── _MAIN_0 seg_001.dat
└── _MAIN_0 seg_001.tran
Manual Backup:
# Create backup archive
tar -czf flatnotes-backup-$(date +%Y%m%d-%H%M%S).tar.gz notes/ index/
# List backup files
ls -lh flatnotes-backup-*.tar.gzAutomated Backup Script:
#!/usr/bin/env bash
# backup-flatnotes.sh
BACKUP_DIR="/path/to/your/backups"
DATE=$(date +%Y%m%d-%H%M%S)
CONTAINER_NAME="flatnotes-ttr"
# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"
# Backup data from container
docker exec $CONTAINER_NAME tar -czf - /data /data/.flatnotes | gzip > "$BACKUP_DIR/flatnotes-$DATE.tar.gz"
echo "Backup created: $BACKUP_DIR/flatnotes-$DATE.tar.gz"Restore from Backup:
# Stop container
docker-compose down
# Remove existing data (optional)
rm -rf notes/ index/
# Restore from backup
tar -xzf flatnotes-backup-20241030-150000.tar.gz
# Restart container
docker-compose up -d- Access the application: http://localhost:8053
- Log in with credentials from
.envfile - Create a test note to verify functionality:
- Title:
test-note - Content:
# Test Note\n\nThis is a test.
- Title:
- Create a subdirectory note:
- Title:
Linux/docker-setup - Content:
# Docker Setup\n\nInstallation instructions...
- Title:
With subdirectory support, you can organize notes hierarchically:
Examples:
Linux/networking/tcp-ip-basicsDevelopment/python/virtualenv-guideProjects/website-rewrite/requirementsDocumentation/api/authentication-methods
Directory Creation:
- Subdirectories are created automatically
- No manual directory setup required
- Mixed organization (root + subdirectories) supported
View Logs:
# Real-time logs
docker-compose logs -f flatnotes
# Recent logs
docker-compose logs --tail=50 flatnotesUpdate to Latest Version:
# Pull latest changes and rebuild
docker-compose pull
docker-compose up --build -dStop and Start:
# Stop the application
docker-compose down
# Start the application
docker-compose up -dResource Usage:
# Container resource usage
docker stats flatnotes
# Disk usage
du -sh notes/ index/
# Container size
docker images flatnotes-flatnotesPort Already in Use:
# Change port mapping in docker-compose.yaml
ports:
- "8054:8080" # Use 8054 instead of 8053Permission Denied Errors:
# Fix volume permissions
sudo chown -R $USER:$USER notes/ index/
chmod 755 notes/ index/Container Won't Start:
# Check container logs
docker-compose logs flatnotes
# Check for port conflicts
netstat -tulpn | grep 8053
# Rebuild container
docker-compose up --build -d --force-recreateLost Data Recovery:
# Check if volumes exist
docker volume ls | grep flatnotes
# Inspect container volume mounts
docker inspect flatnotes-ttr | grep Mounts
# Recover from backup (see Backup section)Verify Application is Running:
# Check container status
docker-compose ps
# Check if web interface responds
curl -f http://localhost:8053/health
# Expected response: "OK"Verify Subdirectory Feature:
# Test API with subdirectory note
curl -X POST http://localhost:8053/api/notes \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{"title": "test/subdir-note", "content": "# Test\n\nContent"}'
# Expected: Success response with note details- Firewall: Only expose necessary ports (8053)
- Reverse Proxy: Consider using nginx/traefik for production
- HTTPS: Use SSL termination in reverse proxy
- Regular Backups: Schedule automated backups
- Access Control: Use strong authentication credentials
- Volume Security: Ensure proper file permissions
- Secret Management: Rotate FLATNOTES_SECRET_KEY regularly
# Run as non-root user (already configured)
# Container runs as user 5000:5000
# Minimal base image
# Uses official Python slim image
# Read-only filesystem where possible
# Only data directories are writable- Environment configured with strong credentials
- Backup strategy implemented and tested
- SSL/HTTPS configured (if using reverse proxy)
- Firewall rules properly configured
- Monitoring set up (logs, metrics)
- Disaster recovery plan documented
- Performance testing completed
- User access tested and verified
- Verify all features working correctly
- Test subdirectory creation and access
- Confirm search functionality across directories
- Validate backup/restore procedures
- Document custom configurations for your environment
- Train users on subdirectory organization