Deploying Funkwhale
Introduction
Funkwhale is a self-hosted, open-source music server and federated audio platform that lets you stream, share, and discover music across the Fediverse. Built with Python and Django, Funkwhale provides robust features including audio library management, podcast hosting, federation with other instances, user playlists, and ActivityPub support. This comprehensive guide walks you through deploying Funkwhale on Klutch.sh using Docker, providing a scalable and production-ready music streaming solution.
Whether you’re building a personal music library, hosting podcasts, or creating a community audio platform, deploying Funkwhale on Klutch.sh gives you the infrastructure and reliability needed for modern audio streaming. This guide covers everything from basic setup to production configurations, including Docker deployment, persistent storage, database setup, environment variables, and security best practices.
Prerequisites
Before deploying Funkwhale, ensure you have:
- A Klutch.sh account
- A GitHub repository for your Funkwhale deployment
- Basic knowledge of Docker and PostgreSQL
- (Recommended) A PostgreSQL database for production use
- (Optional) A Redis instance for caching and background tasks
Understanding Funkwhale Architecture
Funkwhale consists of several key components:
- API Server: Django-based REST API that handles all application logic (default port: 5000)
- PostgreSQL Database: Stores metadata, user data, and application state
- Redis: Provides caching and message brokering for Celery background tasks
- Media Storage: File system or object storage for audio files, album art, and user uploads
- Celery Workers: Process background tasks like audio imports and transcoding
For Klutch.sh deployments, we’ll focus on containerizing the API server while connecting to managed database services.
Creating Your Dockerfile
Klutch.sh automatically detects a Dockerfile in your repository root and uses it for deployment. Here’s a production-ready Dockerfile for Funkwhale:
Basic Dockerfile
FROM funkwhale/funkwhale:latest
# Expose the API portEXPOSE 5000
# The official image includes necessary entrypointsCMD ["./docker-entrypoint.sh"]This basic Dockerfile uses the official Funkwhale image which includes all dependencies pre-configured.
Production Dockerfile with Customizations
For production deployments with additional features:
FROM funkwhale/funkwhale:1.4.0
# Install additional system dependenciesRUN apt-get update && apt-get install -y \ ffmpeg \ curl \ postgresql-client \ && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Create directories for persistent dataRUN mkdir -p /srv/funkwhale/data/media \ /srv/funkwhale/data/music \ /srv/funkwhale/data/staticfiles && \ chown -R funkwhale:funkwhale /srv/funkwhale/data
# Expose API portEXPOSE 5000
# Health checkHEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD curl -f http://localhost:5000/ || exit 1
CMD ["./docker-entrypoint.sh"]This production Dockerfile:
- Pins to a specific version for reproducibility
- Installs ffmpeg for audio processing
- Creates persistent data directories
- Sets proper file permissions
- Includes health checks for monitoring
Configuring Persistent Storage
Funkwhale requires persistent volumes to store user uploads, music files, and static assets. In the Klutch.sh dashboard, configure the following volumes:
Required Volumes
-
Media Storage - User uploads, album art, and processed audio:
- Mount Path:
/srv/funkwhale/data/media - Recommended Size: 50GB (adjust based on expected library size)
- Mount Path:
-
Music Library - Imported music collection:
- Mount Path:
/srv/funkwhale/data/music - Recommended Size: Based on your music collection
- Mount Path:
-
Static Files - Django static assets and frontend files:
- Mount Path:
/srv/funkwhale/data/staticfiles - Recommended Size: 5GB
- Mount Path:
Important: Without persistent volumes, all user uploads and imported music will be lost when the container restarts.
Database Configuration
Funkwhale requires PostgreSQL as its primary database. You have two options:
Option A: Managed PostgreSQL Service
Use an external managed PostgreSQL service (recommended):
- Provision a PostgreSQL 12+ database from your provider
- Create the Funkwhale database:
CREATE DATABASE funkwhale WITH ENCODING 'UTF8';
- Create a dedicated user:
CREATE USER funkwhale_user WITH PASSWORD 'secure_password_here';GRANT ALL PRIVILEGES ON DATABASE funkwhale TO funkwhale_user;
Option B: PostgreSQL on Klutch.sh
Deploy PostgreSQL as a separate application on Klutch.sh and connect via internal networking.
Environment Variables
Configure these environment variables in the Klutch.sh dashboard. Mark sensitive values as secrets to prevent logging.
Essential Variables
# Django ConfigurationDJANGO_SECRET_KEY=your-random-secret-key-min-50-charsDJANGO_ALLOWED_HOSTS=example-app.klutch.sh,*.klutch.shFUNKWHALE_HOSTNAME=example-app.klutch.shFUNKWHALE_PROTOCOL=https
# Database ConfigurationDATABASE_URL=postgresql://funkwhale_user:password@postgres-host:5432/funkwhale
# Redis Configuration (if using)REDIS_URL=redis://redis-host:6379/0CELERY_BROKER_URL=redis://redis-host:6379/1
# Storage PathsMEDIA_ROOT=/srv/funkwhale/data/mediaMUSIC_DIRECTORY_PATH=/srv/funkwhale/data/musicSTATIC_ROOT=/srv/funkwhale/data/staticfilesOptional Variables
# Email ConfigurationEMAIL_CONFIG=smtp+ssl://user:password@smtp.example.com:465
# S3-Compatible Object Storage (alternative to local storage)AWS_ACCESS_KEY_ID=your-access-keyAWS_SECRET_ACCESS_KEY=your-secret-keyAWS_STORAGE_BUCKET_NAME=funkwhale-mediaAWS_S3_ENDPOINT_URL=https://s3.example.com
# FederationFEDERATION_ENABLED=trueFEDERATION_COLLECTION_PAGE_SIZE=50
# SecurityCSRF_TRUSTED_ORIGINS=https://example-app.klutch.shNixpacks Customization
If you need to customize the build or start command, use Nixpacks environment variables:
# Custom start commandNIXPACKS_START_CMD=./docker-entrypoint.sh
# Custom build commandNIXPACKS_BUILD_CMD=python manage.py collectstatic --noinputDeploying to Klutch.sh
Follow these steps to deploy Funkwhale:
-
Prepare Your Repository
- Create a GitHub repository for your Funkwhale deployment
- Add your Dockerfile to the repository root
- Commit and push your changes
-
Create Application
- Navigate to klutch.sh/app
- Click “Create New App”
- Connect your GitHub repository
-
Configure Network Settings
- Select HTTP as the traffic type
- Set internal port to 5000 (Funkwhale’s default API port)
-
Add Persistent Volumes
- Add volumes for media, music, and static files as described above
- Specify mount path and size for each volume
-
Set Environment Variables
- Add all required environment variables from the section above
- Mark passwords and keys as secrets
- Ensure
FUNKWHALE_HOSTNAMEmatches your app URL
-
Deploy
- Click “Deploy” to start the build process
- Klutch.sh automatically detects your Dockerfile and builds the image
- Monitor build logs for any errors
-
Initialize Database
- Once deployed, run migrations via container console:
Terminal window python manage.py migrate - Create superuser account:
Terminal window python manage.py createsuperuser
- Once deployed, run migrations via container console:
-
Access Your Instance
- Open
https://example-app.klutch.shin your browser - Log in with your superuser credentials
- Complete the initial setup wizard
- Open
Post-Deployment Configuration
Importing Your Music Library
- Upload music files to the
/srv/funkwhale/data/musicvolume - Import files via the container console:
Terminal window python manage.py import_files /srv/funkwhale/data/music --in-place --async - Monitor import progress in the Funkwhale admin interface
Enabling Federation
If you want to federate with other Funkwhale instances:
- Set
FEDERATION_ENABLED=truein environment variables - Configure your instance domain in admin panel
- Enable ActivityPub federation under Settings → Federation
- Add trusted instances to your allowlist
User Registration Settings
- Navigate to Settings → Instance in admin panel
- Configure registration policy (open, approval-based, or invite-only)
- Set upload quotas per user
- Configure moderation settings
Custom Domain Setup
To use a custom domain:
- In Klutch.sh dashboard, go to your app’s domain settings
- Add your custom domain (e.g.,
music.yourdomain.com) - Update DNS records:
- Add CNAME record pointing to your Klutch.sh app URL
- Or add A record to the provided IP address
- Update environment variables:
FUNKWHALE_HOSTNAME=music.yourdomain.comDJANGO_ALLOWED_HOSTS=music.yourdomain.comCSRF_TRUSTED_ORIGINS=https://music.yourdomain.com
- Redeploy the application
Klutch.sh automatically provisions TLS certificates for custom domains.
Backup and Disaster Recovery
Database Backups
Regular database backups are critical:
# Create backuppg_dump -h postgres-host -U funkwhale_user -d funkwhale > backup-$(date +%Y%m%d).sql
# Restore backuppsql -h postgres-host -U funkwhale_user -d funkwhale < backup-20240101.sqlMedia Files Backup
- Use cloud provider snapshots for persistent volumes
- Or sync to object storage:
Terminal window rclone sync /srv/funkwhale/data/media s3:bucket/funkwhale-backup/
Automated Backup Strategy
- Schedule daily database dumps
- Sync media files to object storage weekly
- Keep 30 days of backups
- Test restore procedures monthly
Performance Optimization
Database Optimization
- Use connection pooling (PgBouncer)
- Run
VACUUM ANALYZEweekly - Monitor slow queries and add indexes
Redis Caching
Configure Redis for improved performance:
REDIS_MAX_MEMORY=2gbCACHE_URL=redis://redis-host:6379/2CDN for Media Delivery
- Configure S3-compatible storage backend
- Enable CDN (CloudFront, CloudFlare, etc.)
- Set
AWS_S3_CUSTOM_DOMAINto CDN URL
Security Best Practices
Application Security
-
Keep Funkwhale Updated
- Monitor release notes
- Test updates in staging first
- Apply security patches promptly
-
Strong Secrets
- Use cryptographically random values for
DJANGO_SECRET_KEY - Generate with:
openssl rand -base64 50 - Rotate secrets periodically
- Use cryptographically random values for
-
Database Security
- Use strong passwords
- Restrict database access by IP
- Enable SSL/TLS for connections
-
User Permissions
- Use approval-based registration for new instances
- Set reasonable upload quotas
- Enable moderation tools
Network Security
- Keep
DJANGO_ALLOWED_HOSTSrestrictive - Use HTTPS only (enforced by Klutch.sh)
- Configure proper CORS settings
- Implement rate limiting for API endpoints
Troubleshooting
App Won’t Start
Symptoms: Container crashes after deployment
Solutions:
- Check logs in Klutch.sh dashboard
- Verify all environment variables are set
- Test database connectivity:
Terminal window psql $DATABASE_URL -c "SELECT 1" - Check volume permissions
Database Connection Errors
Symptoms: “could not connect to server” errors
Solutions:
- Verify
DATABASE_URLformat is correct - Test connection from container
- Check PostgreSQL allows connections from Klutch.sh
- Verify user permissions
Audio Files Won’t Play
Symptoms: Files upload but streaming fails
Solutions:
- Verify ffmpeg is installed in container
- Check media file permissions
- Ensure
MEDIA_ROOTvolume is writable - Review logs for transcoding errors
Scaling Your Instance
Horizontal Scaling
- Deploy separate Celery worker containers
- Use Redis for task queue
- Deploy multiple API containers with load balancing
- Use shared storage for media files
Vertical Scaling
- Increase CPU for better transcoding performance
- Add RAM for caching and Django performance
- Expand storage volumes as library grows
Advanced Configuration
External Storage
Configure S3-compatible storage:
AWS_ACCESS_KEY_ID=your-keyAWS_SECRET_ACCESS_KEY=your-secretAWS_STORAGE_BUCKET_NAME=funkwhale-mediaAWS_S3_REGION_NAME=us-east-1DEFAULT_FILE_STORAGE=storages.backends.s3boto3.S3Boto3StorageCustom Branding
- Add custom CSS in admin panel
- Upload custom logos
- Configure instance description
- Set custom colors and themes
LDAP Authentication
LDAP_ENABLED=trueLDAP_SERVER_URI=ldap://ldap.example.comLDAP_BIND_DN=cn=admin,dc=example,dc=comLDAP_BIND_PASSWORD=passwordLDAP_USER_SEARCH_BASE_DN=ou=users,dc=example,dc=comResources
Official Documentation
Klutch.sh Documentation
Community
Conclusion
Deploying Funkwhale on Klutch.sh provides a powerful, scalable solution for self-hosted music streaming. With Docker containerization, persistent storage, and managed infrastructure, you can focus on building your music library and community rather than managing servers. Whether you’re running a personal music server or a federated audio platform, Klutch.sh delivers the performance and reliability needed for production workloads.
For additional support, refer to the Funkwhale community forums and Klutch.sh documentation. Happy streaming!