Skip to main content

Overview

This template provides a production‑ready Mastodon instance as a Monk runnable. You can:
  • Run it directly to host your own decentralized social network instance
  • Inherit it in your own runnable to seamlessly add Mastodon to your community infrastructure
Mastodon is free, open-source, decentralized social network software. It’s part of the Fediverse, allowing users on different servers to interact. Think of it as self-hosted Twitter/X with no central authority.

What this template manages

  • Mastodon web application (port 3000)
  • Mastodon streaming server (port 4000)
  • Sidekiq background workers
  • PostgreSQL database for data persistence
  • Redis for caching and job queues
  • Persistent volumes for media and database
  • Optional Elasticsearch for full-text search

Quick start (run directly)

  1. Load templates
  1. Run Mastodon stack
  1. Create admin user
  1. Customize credentials (recommended via inheritance)
Running directly uses the defaults defined in this template’s variables. Secrets added with monk secrets add will not affect this runnable unless you inherit it and reference those secrets.
  • Preferred: inherit and replace variables with secret("...") as shown below.
  • Alternative: fork/clone and edit the variables in mastodon/stack.yaml, then monk load MANIFEST and run.
Once started, access Mastodon at http://localhost:3000 (or the runnable hostname inside Monk networks).

Configuration

Key variables you can customize in this template:
Data is persisted under ${monk-volume-path}/mastodon, ${monk-volume-path}/postgres, and ${monk-volume-path}/redis on the host. Inherit the Mastodon runnable in your community infrastructure. Example:
Generate required secrets:
Then set the secrets once and run your community stack:

Ports and connectivity

  • Service: web on TCP port 3000 (Web UI)
  • Service: streaming on TCP port 4000 (Streaming API)
  • For federation, requires public domain with HTTPS configured
  • From other runnables in the same process group, use connection-hostname("\<connection-name>") to resolve services.

Persistence and configuration

  • Media files: ${monk-volume-path}/mastodon/public:/mastodon/public
  • PostgreSQL data: ${monk-volume-path}/postgres:/var/lib/postgresql/data
  • Redis data: ${monk-volume-path}/redis:/data
  • Ensure the host volumes are writable by the container user.

Production requirements

For production deployment:
  • Domain: Registered domain with DNS pointing to your server
  • HTTPS: SSL/TLS certificate (Let’s Encrypt recommended)
  • Email: SMTP server for notifications and confirmations
  • Object Storage: S3-compatible storage for media (recommended for scalability)
  • CDN: Content delivery network for media (optional but recommended)
  • Backups: Regular database and media backups
  • High‑availability setup: see the mastodon-ha/ template in this repository for a clustered deployment.
  • Combine with monitoring tools (prometheus-grafana/) for observability.

Troubleshooting

  • If you changed secrets but the container has existing data, you may need to regenerate them or update the database.
  • Ensure the host volumes are writable by the container user.
  • Check logs:
  • For federation issues:
    • Verify domain is publicly accessible with HTTPS
    • Test ActivityPub endpoint: https://yourdomain/.well-known/webfinger
  • For email issues, verify SMTP configuration in admin panel
  • For slow performance, scale Sidekiq workers or optimize PostgreSQL
  • Run database migrations if needed:
  • Common administration tasks: