What is Mastodon
Mastodon is a free and open-source decentralized social network that offers an alternative to mainstream platforms like Twitter. It is part of Fediverse. The individual Mastodon instances are not isolated. They can communicate with each other using a standard protocol called ActivityPub. This interconnected network of servers, including Mastodon instances and other compatible platforms (like Pixelfed for photos or PeerTube for videos), is collectively known as the “Fediverse” (a portmanteau of “federation” and “universe”).
My motivation to Run Mastodon server
- Its better twitter alternative for me.
- I don’t like X’s latest policy decisions as a consumer.
- X feels more authoritative, where people join to get updates from celebrity users. Normal users are second-class citizens, made to consume the tweets from celebrities.
- Mastodon provides a publicly visible timeline without the user needing to create an account on any server.
- If you own a Mastodon instance, you can show your favorite tags on the front page.
Result
Prerequisite in My Setup
- Docker with Portainer
- Cloudflare Tunnels
- MobaXterm
How to Run
After briefed research I found most successful docker-compose file from internet was on blog by – Ben Tasker
Link to blog – https://www.bentasker.co.uk/posts/blog/general/running-mastodon-in-docker-compose.html
My Docker compose
version: '3'
networks:
toot_external_network:
toot_internal_network:
internal: true
services:
toot-db:
restart: unless-stopped
image: postgres:14-alpine
container_name: toot-postgres
shm_size: 256mb
networks:
- toot_internal_network
healthcheck:
test: ['CMD', 'pg_isready', '-U', 'postgres']
volumes:
- /mnt/docker/volumes/toot/postgres14:/var/lib/postgresql/data
environment:
- 'POSTGRES_HOST_AUTH_METHOD=trust'
toot-redis:
restart: unless-stopped
image: redis:7-alpine
container_name: toot-redis
networks:
- toot_internal_network
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
volumes:
- /mnt/docker/volumes/toot/redis:/data
toot-web:
image: tootsuite/mastodon:v4.0.2
restart: unless-stopped
container_name: toot-web
env_file: .env.production
command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000"
networks:
- toot_external_network
- toot_internal_network
healthcheck:
test: ['CMD-SHELL', 'wget -q --spider --proxy=off localhost:3000/health || exit 1']
ports:
- 3000:3000
depends_on:
- toot-db
- toot-redis
volumes:
- /mnt/docker/volumes/toot/public/system:/mastodon/public/system
toot-streaming:
image: tootsuite/mastodon:v4.0.2
restart: unless-stopped
container_name: toot-streaming
env_file: .env.production
command: node ./streaming
networks:
- toot_external_network
- toot_internal_network
healthcheck:
# prettier-ignore
test: ['CMD-SHELL', 'wget -q --spider --proxy=off localhost:4000/api/v1/streaming/health || exit 1']
ports:
- 4000:4000
depends_on:
- toot-db
- toot-redis
toot-sidekiq:
image: tootsuite/mastodon:v4.0.2
restart: unless-stopped
container_name: toot-sidekiq
env_file: .env.production
command: bundle exec sidekiq
depends_on:
- toot-db
- toot-redis
networks:
- toot_external_network
- toot_internal_network
volumes:
- /mnt/docker/volumes/toot/public/system:/mastodon/public/system
healthcheck:
test: ['CMD-SHELL', "ps aux | grep '[s]idekiq\\ 6' || false"]
References
- https://www.youtube.com/watch?v=9JR1IBRA4RQ
- https://www.bentasker.co.uk/posts/blog/general/running-mastodon-in-docker-compose.html
- https://www.reddit.com/r/selfhosted/comments/yv9296/easiest_allinone_docker_compose_to_deploy_mastodon/

