How to Install Mastodon on Your Synology NAS

How to Install Mastodon on Your Synology NAS

Mastodon is a free, open-source social network server based on ActivityPub where users can follow friends and discover new ones. On Mastodon, users can publish anything they want: links, pictures, text, video. All Mastodon servers are interoperable as a federated network (users on one server can seamlessly communicate with users from another one, including non-Mastodon software that implements ActivityPub like Pixelfed and WriteFreely). In this step by step guide I will show you how to install Mastodon on your Synology NAS using Docker and Portainer.

💡Note: This guide works perfectly with the latest Mastodon v4.1.2 release.

  • STEP 1

Please Support My work by Making a Donation.

  • STEP 2

Install Portainer using my step by step guide. If you already have Portainer installed on your Synology NAS, skip this STEP. Attention: Make sure you have installed the latest Portainer version.

  • STEP 3

Make sure you have a synology.me Wildcard Certificate. Follow my guide to get a Wildcard Certificate. If you already have a synology.me Wildcard certificate, skip this STEP.

  • STEP 4

Go to Control Panel / Login Portal / Advanced Tab / click Reverse Proxy. Follow the instructions in the image below.

Mastodon Synology NAS Set up 1

  • STEP 5

Now click the “Create” button. Follow the instructions in the image below.

Mastodon Synology NAS Set up 2

  • STEP 6

After you click the Create button, the window below will open. Follow the instructions in the image below.

On the General area, set the Reverse Proxy Name description: type in Mastodon. After that, add the following instructions:

Source:
Protocol: HTTPS
Hostname: mastodon.yourname.synology.me
Port: 443

Check Enable HSTS

Destination:
Protocol: HTTPS
Hostname: localhost
Port: 8562

Mastodon Synology NAS Set up 3 new

  • STEP 7

On the Reverse Proxy Rules click the Custom Header tab. Click Create and then, from the drop-down menu, click WebSocket. After you click on WebSocket, two Header Names and two Values will be automatically added. Click Save. Follow the instructions in the image below.

Synology Proxy WebSocket

  • STEP 8

Go to Control Panel / Network / Connectivity tab/ Check Enable HTTP/2 then click Apply. Follow the instructions in the image below.

Mastodon Synology NAS Set up 4

  • STEP 9

Go to Control Panel / Security / Advanced tab/ Check Enable HTTP Compression then click Apply. Follow the instructions in the image below.

Mastodon Synology NAS Set up 5

  • STEP 10

Go to File Station and open the docker folder. Inside the docker folder, create one new folder and name it mastodon. Follow the instructions in the image below.
Note: Be careful to enter only lowercase, not uppercase letters.

Mastodon Synology NAS Set up 6

  • STEP 11

Now create three new folders inside the mastodon folder that you created at STEP 10 and name them config, db, redis. Follow the instructions in the image below.
Note: Be careful to enter only lowercase, not uppercase letters.

Mastodon Synology NAS Set up 7

  • STEP 12

Log into Portainer using your username and password. On the left sidebar in Portainer, click on Stacks then + Add stack. Follow the instructions in the image below.

1 Synology Portainer Add Stack

  • STEP 13

In the Name field type in mastodon. Follow the instructions in the image below.

Note: Copy Paste the code below in the Portainer Stacks Web editor.

version: "3.9"
services:
  mastodon-redis:
    image: redis
    container_name: Mastodon-REDIS
    hostname: mastodon-redis
    security_opt:
      - no-new-privileges:true
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping || exit 1"]
    user: 1026:100
    environment:
      - TZ=Europe/Bucharest
    volumes:
      - /volume1/docker/mastodon/redis:/data
    restart: always

  mastodon-db:
    image: postgres
    container_name: Mastodon-DB
    hostname: mastodon-db
    security_opt:
      - no-new-privileges:true
    healthcheck:
      test: ["CMD", "pg_isready", "-q", "-d", "mastodon", "-U", "mastodonuser"]
      timeout: 45s
      interval: 10s
      retries: 10
    user: 1026:100
    volumes:
      - /volume1/docker/mastodon/db:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: mastodon
      POSTGRES_USER: mastodonuser
      POSTGRES_PASSWORD: mastodonpw
    restart: always
    
  mastodon:
    image: lscr.io/linuxserver/mastodon:latest
    container_name: Mastodon
    hostname: mastodon
    security_opt:
      - no-new-privileges:true
    environment:
      - PUID=1026
      - PGID=100
      - TZ=Europe/Bucharest
      - DEFAULT_LOCALE=en
      - LOCAL_DOMAIN=mastodon.yourname.synology.me
      - WEB_DOMAIN=mastodon.yourname.synology.me
      - REDIS_HOST=mastodon-redis
      - REDIS_PORT=6379
      - DB_HOST=mastodon-db
      - DB_USER=mastodonuser
      - DB_NAME=mastodon
      - DB_PASS=mastodonpw
      - DB_PORT=5432
      - ES_ENABLED=false
      - ES_HOST=es
      - ES_PORT=9200
      - ES_USER=elastic
      - ES_PASS=elastic
      - SECRET_KEY_BASE=2e80b1b7d3a70f6358ab08a1cebdffc2424d8800c8ff764ff238f892abd539ff70000f31310d21ac7391d281795479b6d97263edd5d88c05070b6b8acbadf2ab
      - OTP_SECRET=eca299ae599a9b4eda009b2abfc1ee5b01e0ca30eea060f2a47c6ca3075c4d3616df992ae7e437fcd061aeb6dc9f9cc3d38e79ab090324092777984478996c06
      - S3_ENABLED=false
    volumes:
      - /volume1/docker/mastodon/config:/config
    ports:
      - 8562:443
    restart: always
    depends_on:
      mastodon-redis:
        condition: service_healthy
      mastodon-db:
        condition: service_started

Note: Before you paste the code above in the Web editor area below, change the value numbers for user with your own UID and GID values. (Follow my step by step guide on how to do this.) 1026 is my personal UID value and 100 is my personal GID value. You have to type in your own values.
Note: Before you paste the code above in the Web editor area below, change the value for TZ. (Select your current Time Zone from this list.)
Note: Before you paste the code above in the Web editor area below, change the value numbers for PUID and PGID with your own values. (Follow my step by step guide on how to do this.) 1026 is my personal PUID value and 100 is my personal PGID value. You have to type in your own values.
Note: Before you paste the code above in the Web editor area below, change the value for LOCAL_DOMAIN and type in your own synology.me DDNS that you have previously created at STEP 6.
Note: Before you paste the code above in the Web editor area below, change the value for WEB_DOMAIN and type in your own synology.me DDNS that you have previously created at STEP 6.

Mastodon Synology NAS Set up 8

  • STEP 14

Scroll down on the page until you see a button named Deploy the stack. Click on it. Follow the instructions in the image below. The installation process can take up to a few minutes. It will depend on your Internet speed connection.

Mastodon Synology NAS Set up 9 new 2023

  • STEP 15

If everything goes right, you will see the following message at the top right of your screen: “Success Stack successfully deployed“.

Mastodon Synology NAS Set up 10

  • STEP 16

On the left sidebar in Portainer, click Containers. Identify your Mastodon instance, then click on the little terminal icon. Follow the instructions in the image below.

Mastodon Synology NAS Set up 11

  • STEP 17

After you click on the little terminal icon at STEP 16, a new page will open. Click Connect. Follow the instructions in the image below.

Mastodon Synology NAS Set up 12

  • STEP 18

After you click Connect at STEP 17, a Console will open. Copy Paste the code below and follow the instructions in the image.

tootctl accounts create marius --email yourownemail --confirmed --role Owner

Note: Before you paste the code above in the Console area below, change marius with your own name.
Note: Before you paste the code above in the Console area below, change yourownemail text with your email.

Mastodon Synology NAS Set up 13 new

  • STEP 19

Once the code is inserted, confirm by pressing Enter on your keyboard to start the process of password creation. After some seconds, you will get a new password for the user you have previously created at STEP 18. Copy the password and save it in a safe place – you will need it later.

Mastodon Synology NAS Set up 14

  • STEP 20

Go back to STEP 1 or you will deal with karma 🙂.

  • STEP 21

Now open your browser and type in your HTTPS/SSL certificate like this https://mastodon.yourname.synology.me that you have previously created at STEP 6. In my case it’s https://mastodon.mariushosting.synology.me If everything goes right, you will see the main Mastodon page. Click Sign in. Follow the instructions in the image below.

Mastodon Synology NAS Set up 15

  • STEP 22

On the E-mail address field type in the email you have chosen at STEP 18. On the Password field type in the password you have previously generated automatically at STEP 19. Click LOG IN. Follow the instructions in the image below.

Mastodon Synology NAS Set up 16 new 2023

  • STEP 23

Personalize your own profile, then click Preferences to access your Administration area. Follow the instructions in the image below.

Mastodon Synology NAS Set up 17

  • STEP 24

On the left sidebar click Administration. Follow the instructions in the image below.

Mastodon Synology NAS Set up 18

  • STEP 25

Under Administration, click Server Settings to personalize your Mastodon Server. Follow the instructions in the image below.

Mastodon Synology NAS Set up 19

  • STEP 26

If a new user will subscribe to your Server, you will find it under Moderation in the Accounts area. Click Accounts. Click on the new user profile. Follow the instructions in the image below.

Mastodon Synology NAS Set up 20

  • STEP 27

Click Confirm to confirm the new user. Once the new user is approved, they can start using your Mastodon server. Follow the instructions in the image below.
Note: Owners, Administrators and Moderators can confirm, that is approve, new members.
Note: Just to clarify: every user that will register a new account on your server will need manual confirmation to start using their profile on your Mastodon server. No Email will be sent to the new user when they register for the first time. I decided not to include the SMTP email server (in the docker compose) for automatic confirmation of new users so as not to overload the email server. For this reason, I thought it is only fair that all new users be manually approved by the owner, administrators or moderators so that you have complete control of the users coming to your private Mastodon server. If you want the new users to receive an automatic registration confirmation email, set up a consultation with me.

Mastodon Synology NAS Set up 21

Enjoy your Mastodon Server!

Note: Find out how to update the Mastodon container with the latest image.
Note: Can I run Docker on my Synology NAS? See the supported models.
Note: How to Free Disk Space on Your NAS if You Run Docker.
Note: How to Schedule Start & Stop For Docker Containers.
Note: How to Activate Email Notifications.
Note: How to Add Access Control Profile on Your NAS.
Note: How to Change Docker Containers Restart Policy.
Note: How to Use Docker Containers With VPN.
Note: Convert Docker Run Into Docker Compose.
Note: How to Clean Docker.
Note: How to Clean Docker Automatically.
Note: Best Practices When Using Docker and DDNS.
Note: Some Docker Containers Need WebSocket.
Note: Find out the Best NAS Models For Docker.
Note: Activate Gmail SMTP For Docker Containers.

This post was updated on Tuesday / April 11th, 2023 at 11:12 PM