Mastodon Docker Install

Mastodon on Synology NAS, via Docker. I've been doing a little bit of research and I find myself hitting a brick wall. I don't have any experience with Docker, but I'm trying to get my head around it, so I can install an instance of Mastodon on my Synology. It's doing my head in. Mastodon is a part of Fediverse, allowing users to interact with users on other platforms that support the same protocol for example: PeerTube, Friendica and GNU Social. Mastodon provides the possibility to use S3 compatible Object Storage to store media content uploaded to instances, making it flexible and scalable. A minimal set of commands I had to do to successfully run Mastodon via docker-compose on the VPS. Many OS specific configurations are omitted, as I decided to use Arch on this VPS as well, which is not what most people choose for their server environment, at least not when caveats of such choice play a major role. But of course that is the result of attempting to docker-compose up after your arcane words of power. The result of that spell was actually this: /home/mastodon# docker-compose run -rm web rails db:schema:load. Establish SSH Connection then install Docker. Set up code with Docker Compose. Install Mastodon. Next, add your Mailgun account. Make sure Nginx is enabled. Get an SSL Certificate and launch Mastodon. Automate Tasks and Administer Mastodon. You’re done and you can start inviting users to sign up for their accounts using your server.

What is Mastodon?

Mastodon is a microblogging platform akin to others you may have seen, such as Twitter, but instead of being centralised it is a federated network which operates in a similar way to email.

Like email, you choose your server and whether it’s GMail, Outlook, iCloud, wherever you sign up you know you’ll be able to email everyone you need to so long as you know their address.

The word “instance” is often used on Mastodon as a synonym of server.

This means there’s no big uncaring company running it all, no shareholders, no central control, none of the targeted advertising we’re all fed up with, just a bunch of people sharing the things they want to share with each other.


What is this Guide?

This Guide will show you how to migrate an existing Mastodon dockerized instance to a new Server without docker. Please read the complete Guide carefully before you start to migrate and if possible test it before live migration.
You can also synchronize the files more than once to reduce the time required for live migration. The Installation on the new server without docker is documented here. but don’t run mastodon:setup.

  • root-access via ssh
  • Mastodon installed via Guide without mastodon:setup
On the old Server

I assume that Mastodon is running in the directory ~/mastodon/, otherwise please adjust in the commands. The container names also depend on the directory-name.

Step 1: Stop Mastodon

You have to stop the following containers manually, mastodon_streaming_1, mastodon_sidekiq_1 and mastodon_web_1:

Step 2: Create Database dump

The following command will put the dump into the directory ~/mastodon/postgres/

Wait a moment and then check if dump was created:

Then stop the complete stack with:

On the new Server
Step 3: Sync system-files

If you’re using S3, you can skip this step. Otherwise use rsync to copy the files to your new server, I assume you use mastodon as user.

Step 4: Copy and Edit Configuration

You copy the file .env.production to your new server:

now you have to adjust the settings for the database in .env.production

and set DB_SETTINGS:

Step 5: Copy and Import database

Before importing the database, we have to copy the dump and create an empty Database on the new server:

change to user mastodon and create the empty DB:

Then import the dump:

Step 6: Finish the migration

Before we can start the new server, we have to precompile the assets as user mastodon:

then we rebuild the home timelines for our users:

This can take some time, when finished it is time to start the new server

Step 7: Start Mastodon

You have to change your prompt back to user root and start the services:

you can check the services with:

Do not forget to update your DNS settings to point to the new server and update or copy your Nginx/Apache2 configuration, re-run LetsEncrypt as necessary.

Enjoy your new Server and disable the old one.

Mastodon Docker Install

If you want to run your own fully managed Instance hosted in Germany with 100% green Energy, look here

If you want to use mastodon without your own instance you may register here:

or here:

If you want to contribute to the running costs of this Blog or the running Mastodon-Instances, then you can use the following link:

Mastodon Docker Install

Thx and feel free to contact me 🙂



A minimal set of commands I had to do to successfully run Mastodon viadocker-compose on the VPS. Many OS specific configurations are omitted, asI decided to use Arch on this VPS as well, which is not what most peoplechoose for their server environment, at least not whencaveatsof such choice play a major role.

Getting started

Clone the Mastodon repository. It contains a docker-compose.yml file aswell as other files directly or indirectly referenced by it (for examplepackage.json or yarn.lock):

Now here's what I occasionally do to help me keep track of the changes tothe configuration files easily. Make a branch on a given tag, which at thetime of writing was v3.4.1:


Without creating a branch, the HEAD would be in a detached state (pointingat a tagged commit, not a branch), It would still track changes, but thesewould not be accessible after another checkout.

Tip: toget the latest available tag easily,you can use git rev-list as follows:

Also consider changing the mastodon image to some tagged version. In thesection web replace mastodon:latest image with the tagged one:

It is useful for referencing and searching for issues, should some arise,at the very least. Even more important to me is that it requires a manualintervention to bump a version number, so things won't suddenly change whenthe docker-compose script get restarted without you understanding why. Itis overall a good practice to avoid unnecessary surprises.

Postgres database

The referenced version of postgres in the docker-compose file is9.6-alpine. This might work, but I tested with 12.5-alpine instead andfound no problems so far, so I changes to this version under the dbsection:

Start the container to setup the user, assuming the path to thedocker-compose file is /home/mastodon/mastodon/docker-compose.yml. Ifnot, modify the path so the postgres volume folder matches it. Considersetting a custom password:

Create a mastodon database user, use the password from above:

This makes database setup complete.

Mastodon Docker Install In Java

Set up Mastodon

This part is a little bit tricky, as it took me the most time to figure outright:

Fill the domain name you intend to run the instance. This one is probablyhard to change once the instance is running. Fill the next questionsaccording to the table below:

QuestionType in
Do you want to enable single user mode?No
Are you using Docker to run Mastodon?Yes
PostgreSQL host:mastodon_db_1
PostgreSQL port:5432
Name of PostgreSQL database:mastodon
Name of PostgreSQL user:mastodon
Password of ProstgreSQL user:password

The above part should look like this in the terminal:

The setup then continues with email capabilities configuration questions. Iam omitting details for this part, as my emailprovider required different SMTP settings,some of which were not offered via this setup wizard. I have not found areliable way to send a test email from the UI or the console later, so itmight be worth trying here to get the emails sent out. Setting up cloudstorage or email capabilities can be also safely skipped now and configuredlater, if you wish to do so, use these options:

QuestionType in
Do you want to store uploaded files on the cloud?No
Do you want to send e-mails from localhost?Yes
E-mail address to send e-mails 'from':Enter
Send a test e-mail with this configuration right now?No
Save configuration?Yes

Your terminal should resemble this:

Docker Install Windows

The terminal then outputs the configuration, including secret keys. Copyand paste it into .env.production file in the cloned repository alreadycontaining postgres/ directory and docker-compose.yml file, amongothers.

The last part is to migrate the database and create an admin account.Answer Yes to both and proceed. The Mastodon instance admin userpassword will be generated and displayed, make sure to not lose it! If youlose it before logging in successfully, one way to obtain it again is todelete postgres/ folder and start over from thePostgres database step above.

Mastodon Docker Install In Chrome

Full-text search

This step is optional, although it is a nice addition to have a full-textsearch provided via ElasticSearch available. Edit the docker-compose.ymland uncomment two es related blocks:

Edit .env.production file and append the following:

The instance should now be ready to start.

First run

Start the whole stack, this can take a while:

This generates other files and folders, consider setting the permissionsfor them and start the instance again:

Mastodon Docker Install In Windows 10

Now without any modifications on docker-compose.yml the instance shouldbe available under the port 3000. Configure the reverse proxy of yourchoice to terminate the SSL/TLS and to proxy the domain name inserted intothe wizard earlier to this port. You can also find some inspiration abouthow to do so in my previous articles under tags Nginx andespecially, should you choose to use these two tomanage this task and the certificates for you.

To access the web user interface, insert the admin user name and thepassword generated earlier, and you are ready to have fun in the fediverse!