Mastodon

Hosting Jan 4, 2026

Mastodon is a neat microblogging platform similar to Twitter and Threads. I came across it online, reading other people's blogs and seeing links to some Mastodon servers they were on. After conducting research into the application, the concept, and the ideals behind the project, I was sold on it. Mastodon runs on the ActivityPub Protocol, making it compatible with other servers on the Fediverse, a network of servers and applications that support this protocol. I am not too keen on Twitter, especially nowadays, given how the platform has gone and the direction the application itself is heading. With that in mind, I think the idea of microblogging is something I would enjoy and like to participate in. Large platforms can be intimidating or off-putting. While you may have thousands of followers, you could get back 5% of that in engagement. Platforms like Mastodon do not aim to solve issues like that, but I believe a focus on decentralized, smaller but integrated platforms could be the best step forward.

Assumptions

You have knowledge of ports and networking. You know how to use Docker and Docker Compose. You can set up and point your domain to an application. You know how to use environment variables and how to change them. You use another application that handles SSL certificates for your domain. You have the knowledge to adjust the information in this page for your specific use case, as you know everything may not work out-of-the-box on your host.

Setup

There are many ways to set up Mastodon, as outlined in their documentation. I had strict requirements to set up Mastodon on my servers.

x-common-variables: &common-variables
  environment:
    # Federation
    - LOCAL_DOMAIN=example.com
    # Redis
    - REDIS_HOST=redis
    - REDIS_PORT=6379
    # PostgreSQL
    - DB_HOST=db
    - DB_USER=postgres
    - DB_NAME=postgres
    - DB_PASS=
    - DB_PORT=5432      
    # Secrets
    - SECRET_KEY_BASE=
    # Encryption secrets
    - ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=
    - ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=
    - ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=
    # Web Push
    - VAPID_PRIVATE_KEY=
    - VAPID_PUBLIC_KEY=
    # Sending mail
    - SMTP_SERVER=
    - SMTP_PORT=
    - SMTP_LOGIN=
    - SMTP_PASSWORD=
    - SMTP_FROM_ADDRESS=  

    # File storage (optional)
    - S3_ENABLED=false
    - S3_BUCKET=files.example.com
    - AWS_ACCESS_KEY_ID=
    - AWS_SECRET_ACCESS_KEY=
    - S3_ALIAS_HOST=files.example.com

    # IP and session retention
    - IP_RETENTION_PERIOD=31556952
    - SESSION_RETENTION_PERIOD=31556952
services:
  db:
    restart: always
    image: postgres:14-alpine
    shm_size: 256mb
    networks:
      - internal_network
    volumes:
      - /DATA/AppData/mastodon/postgres14:/var/lib/postgresql/data
    environment:
      - 'POSTGRES_HOST_AUTH_METHOD=trust'
  redis:
    restart: always
    image: redis:7-alpine
    networks:
      - internal_network
    volumes:
      - /DATA/AppData/mastodon/redis:/data
 
  web:
    image: ghcr.io/mastodon/mastodon:v4.5.0
    restart: always
    <<: *common-variables
    command: bundle exec puma -C config/puma.rb
    networks:
      - external_network
      - internal_network
    ports:
      - '3000:3000'
    depends_on:
      - db
      - redis
    volumes:
      - /DATA/AppData/mastodon/public/system:/mastodon/public/system

  streaming:
    image: ghcr.io/mastodon/mastodon-streaming:v4.5.0
    restart: always
    <<: *common-variables
    command: node ./streaming/index.js
    networks:
      - external_network
      - internal_network
    ports:
      - '127.0.0.1:4000:4000'
    depends_on:
      - db
      - redis

  sidekiq:
    image: ghcr.io/mastodon/mastodon:v4.5.0
    restart: always
    <<: *common-variables
    command: bundle exec sidekiq
    depends_on:
      - db
      - redis
    networks:
      - external_network
      - internal_network
    volumes:
      - /DATA/AppData/mastodon/public/system:/mastodon/public/system
networks:
  external_network:
  internal_network:
    internal: true

You will need to perform one more task after deploying your new Mastodon stack. Connect to the web container via SSH or through Portainer. You will need to run rails db:setup to configure the DB before Mastodon will actually start. After this, you should have a Mastodon server set up and ready to access once you point your domain to your instance. To make your account, you will need to set up the admin account the same way as well, in the same window, enter:

tootctl accounts create \
  alice \
  --email alice@example.com \
  --confirmed \
  --role Owner

Replace Alice and the email with your respective username for Mastodon. Once this is done, you should be able to log in and complete the Mastodon configuration through the UI.

Tags

Simplicy

I am a 28 year old Software Developer born and raised in South Florida. I make terminal applications, API's, and desktop applications; mostly with Rust. My free time is split between Programming and DevOps, Gaming/Modding, Sewing, or Breadboarding.