← All templates · Social and community
Deploy Mastodon in one click
Your own server in the fediverse: posts, follows and replies across Mastodon and beyond
A self-hosted alternative to X (Twitter).
What is Mastodon?
Mastodon is an open-source social network, a decentralized alternative to X (Twitter) built from independent servers that talk to each other. You write short posts with images, video, polls and content warnings, and follow people on any other server, not just your own. The home feed shows the accounts you follow in time order, with no ads and no algorithm ranking it. Each server sets its own rules: its admin can limit or suspend an account, or block a whole server.
People self-host it for control: their handles end in their own server's address, and their posts and followers live on a machine they run. A server can be one person's microblog, an invite-only space for family and friends, or a community with open sign-ups, which brings moderation work. The catch is email: Mastodon needs an SMTP service to send confirmation links and notifications.
Hosting Mastodon on Pethost
- You sign in to Pethost with a passkey, GitHub or Google. No machine yet? You pick a plan, and the link waits until it is ready.
- New project opens at Mastodon. You fill in what it asks for and click Create project: Username, Email, Admin password.
- In a minute or two Mastodon is live at its own address with HTTPS. Its secrets are made at random, and its data is in the nightly backup.
- It is a project like any other: you or your agent can change it, roll it back or restore it.
Questions about Mastodon
Is Mastodon free and open source?
Yes. Mastodon is free software under the AGPLv3 licence, developed by a non-profit. Running your own server costs no licence fee and nothing per user.
Is there a Mastodon app for iPhone and Android?
Yes. Mastodon has official apps for iOS and Android, and its web app runs in any browser. Third-party apps such as Ivory, Ice Cubes and Tusky work with your own server too.
Can I move my Mastodon account to my own server?
Yes. Create an alias on the new account, then start the move from the old one: your followers come along, your posts stay behind. Follows, lists, blocks and mutes go across as CSV files you export and import.
Can I change my Mastodon server's domain later?
No, not safely: Mastodon's docs warn that other servers would mistake your existing accounts for new ones. Settle on the address, a name under yourname.pethost.app or your own domain, before the first post.
What is the fediverse, and is Mastodon part of it?
The fediverse is all the sites that talk to each other over ActivityPub, an open protocol. Mastodon is one of them, so a Mastodon account can follow and reply to people on Pixelfed, PeerTube or Misskey.
How much memory and disk does Mastodon need?
Mastodon is moderate: about 1.5 GB across six services, and media cached from those you follow grows the disk. On Pethost the Grow plan is enough for it, with room for other apps beside it.
Mastodon Docker Compose file
The template is this compose.yaml and the variables written into the project’s .env as it is created. Pethost runs the file as it is written.
Containers: proxy (caddy:2.10-alpine), web (ghcr.io/mastodon/mastodon:v4.7.3), streaming (ghcr.io/mastodon/mastodon-streaming:v4.7.3), sidekiq (ghcr.io/mastodon/mastodon:v4.7.3), db (postgres:17), redis (redis:7.4).
Volumes, in the nightly backup: system, db, redis.
# Mastodon's docker-compose.yml with a small Caddy in front, which gives the streaming
# API its path on the project's address, as Mastodon's nginx does.
x-env: &env
LOCAL_DOMAIN: ${HOST}
DB_HOST: db
DB_PORT: "5432"
DB_USER: mastodon
DB_NAME: mastodon
DB_PASS: ${DB_PASSWORD}
REDIS_HOST: redis
REDIS_PORT: "6379"
SECRET_KEY_BASE: ${SECRET_KEY_BASE}
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY: ${AR_DETERMINISTIC_KEY}
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT: ${AR_KEY_DERIVATION_SALT}
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY: ${AR_PRIMARY_KEY}
VAPID_SEED: ${VAPID_SEED}
ES_ENABLED: "false"
WEB_CONCURRENCY: "1"
SMTP_SERVER: ${SMTP_SERVER:-}
SMTP_PORT: ${SMTP_PORT:-587}
SMTP_LOGIN: ${SMTP_LOGIN:-}
SMTP_PASSWORD: ${SMTP_PASSWORD:-}
SMTP_FROM_ADDRESS: ${SMTP_FROM_ADDRESS:-}
# Web push needs a VAPID key pair. Its private key is the 32 random bytes of VAPID_SEED,
# and the public key is derived from it, so web and sidekiq read the same pair and
# nothing is kept apart from .env.
x-vapid: &vapid |
eval "$$(ruby -ropenssl -rbase64 -e '
d = [ENV.fetch("VAPID_SEED")].pack("H*")
point = OpenSSL::PKey::EC::Group.new("prime256v1").generator.mul(OpenSSL::BN.new(d, 2))
puts "export VAPID_PRIVATE_KEY=#{Base64.urlsafe_encode64(d)}"
puts "export VAPID_PUBLIC_KEY=#{Base64.urlsafe_encode64(point.to_octet_string(:uncompressed))}"
')"
services:
proxy:
image: caddy:2.10-alpine
restart: unless-stopped
configs:
- source: caddy
target: /etc/caddy/Caddyfile
depends_on:
- web
- streaming
web:
image: ghcr.io/mastodon/mastodon:v4.7.3
restart: unless-stopped
environment:
<<: *env
ADMIN_USERNAME: ${ADMIN_USERNAME}
ADMIN_EMAIL: ${ADMIN_EMAIL}
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
VAPID: *vapid
# Every start migrates the database and seeds what is missing; the first one also
# makes the owner from the username, email and password given. Registrations stay
# closed, Mastodon's default, so nobody else can sign up until the owner opens them.
command:
- sh
- -c
- |
set -e
eval "$$VAPID"
bundle exec rails db:prepare db:seed
bundle exec rails runner '
owner = UserRole.find_by!(name: "Owner")
unless User.exists?(role_id: owner.id)
password = ENV.fetch("ADMIN_PASSWORD")
user = User.create!(
email: ENV.fetch("ADMIN_EMAIL"),
password: password,
password_confirmation: password,
account: Account.new(username: ENV.fetch("ADMIN_USERNAME")),
role: owner,
confirmed_at: Time.now.utc,
agreement: true,
approved: true,
bypass_registration_checks: true
)
# Closed registrations leave a new user waiting for approval.
user.approve!
end
'
exec bundle exec puma -C config/puma.rb
volumes:
- system:/opt/mastodon/public/system
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "curl -s --noproxy localhost localhost:3000/health | grep -q OK"]
interval: 10s
timeout: 5s
retries: 5
start_period: 300s
streaming:
image: ghcr.io/mastodon/mastodon-streaming:v4.7.3
restart: unless-stopped
environment: *env
command: node ./streaming/index.js
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "curl -s --noproxy localhost localhost:4000/api/v1/streaming/health | grep -q OK"]
interval: 10s
timeout: 5s
retries: 5
sidekiq:
image: ghcr.io/mastodon/mastodon:v4.7.3
restart: unless-stopped
environment:
<<: *env
VAPID: *vapid
command:
- sh
- -c
- |
eval "$$VAPID"
exec bundle exec sidekiq
volumes:
- system:/opt/mastodon/public/system
depends_on:
web:
condition: service_healthy
db:
image: postgres:17
restart: unless-stopped
shm_size: 256mb
environment:
POSTGRES_USER: mastodon
POSTGRES_DB: mastodon
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- db:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "mastodon"]
interval: 5s
timeout: 5s
retries: 10
redis:
image: redis:7.4
restart: unless-stopped
volumes:
- redis:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 5s
retries: 10
configs:
# The machine's proxy is trusted for X-Forwarded-Proto, so Rails sees HTTPS.
caddy:
content: |
{
admin off
auto_https off
servers {
trusted_proxies static private_ranges
}
}
:8080 {
reverse_proxy /api/v1/streaming* streaming:4000
reverse_proxy web:3000
}
volumes:
system:
db:
redis:
More in Social and community
- listmonkA newsletter and mailing list manager
- LemmyA link aggregator and forum for the fediverse
- NodeBBA forum for your community
- Apache AnswerQuestions and answers for a community, a help center or a team, a Stack Overflow of your own
- MattermostOpen-source team chat with channels, threads, file sharing and integrations
- PixelfedPhoto sharing without ads or algorithms, an Instagram alternative that federates with Mastodon