How to run a Mastodon instance simply with Docker

Share this post on:

You can get latest configurations and files from official Mastodon repository on GitHub where you can find docker-compose.yml and .env.production as well.

To generate hash codes using rake secret and other configuration files, you will need Ruby libraries installed; but it is possible to keep the host machine clean with running your commands inside a temporary container based on Mastodon image. Just attach to the shell using the command below and run the following scripts, to achieve their goals.

docker run -ti --entrypoint /bin/bash ghcr.io/mastodon/mastodon:v4.2.0

You may enter the commands in the available bash:

bin/rails db:create
rake secret
rake mastodon:webpush:generate_vapid_key

The first command will generate the database, second one will return secret and the last one will generate webpush hash strings.

Copy and paste contents of the .env.production file from repo, and write it to a file with your preferred name. Personally I will not store my Docker environment files in a dot file, because I do a lot of migrations, and dot files can increase human error due to their hidden file manager attribute. If you agree, the docker-compose should link to env instead of .env.production.

At last, if only the docker-compose.yml is grabbed (and not the whole repo) remove those lines pointing to local Dockerfile for build in the .yml.

There are optional configurations such as memory over-commit for Redis. When the Redis is up, run docker cp my_mastodon_container:/etc/sysctl.conf sysctl.conf, this will create a Linux systemctl config file based on Redis image, then prepend vm.overcommit_memory=1 to the file and map from the .yml like ./sysctl.conf:/etc/sysctl.conf:ro.

Share this post on:

Author: tayyebi

Tayyebi works in the role of Director at Gordarg where he is the founder. He is passionate about people, technology, and arts. Mohammad believes in communications, each of us has the power to empower their people with knowledge. He can be seen writing codes, playing music, biking, and reading.

View all posts by tayyebi >






www.Gordarg.com