Mastodon
Mastodon is a free, open-source social network server based on ActivityPub. Follow friends and discover new ones. Publish anything you want: links, pictures, text, video. All servers of Mastodon are interoperable as a federated network, i.e. users on one server can seamlessly communicate with users from another one. This includes non-Mastodon software that also implements ActivityPub! The easiest way to get started on Mastodon is to join one of the existing servers, but here at OD we're running our own instance which we're documenting here.
Contents
Installation
Mastodon has a lot of dependencies that we don't have installed on our server such as PostgreSQL and Ruby, so for us the Docker image is definitely the preferred route, but it's till quite complicated and needs to be done via Docker Compose based on the official installation.
Clone the Docker repo
First, create a mastodon group with number 991 which is used by the project, then create a directory for the persistent data that will be used by the containers (we're putting our repo and data in /var/www/domains along with other web applications - this is not under our document root!), clone the Mastodon Docker repo and checkout the latest stable version.
groupadd -g 991 mastodon
useradd -u 991 -g 991 -c "Mastodon User" -s /usr/bin/nologin -d /var/www/domains/mastodon-data mastodon
mkdir /var/www/domains/mastodon-data
cd /var/www/domains
git clone https://github.com/tootsuite/mastodon.git mastodon-docker
chown -R mastodon:mastodon /var/www/domains/mastodon*
cd mastodon-docker
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
docker-compose.yml
Before running any docker-compose commands we need to edit the docker-compose.yml file. Change all the images to use the version of the repo you chose above, e.g. "image: tootsuite/mastodon:v2.2.0". Uncomment all the volume path lines for data persistence. The host part (the path before the colon) of each needs to be changed to the absolute data path you set above (in our case /var/www/domains/mastodon-data) instead of just a relative "./path". You may want to enable the elastic search section too. I like to change the restart options from "always" to "unless-stopped" as well.
.env.production
Now copy the .env.production.sample to .env.production and run the setup wizard. Note that most of the questions can be just set as default by entering nothing. Answer "yes" to save the configuration, create the schema and admin user etc.
docker-compose run --rm web bundle exec rake mastodon:setup
Start the instance
Then if all has gone well, you can now run the main Mastodon instance with docker-compose up -d which should give something like the following. To stop the instance use docker-compose down. Note that the docker-compose commands must be run from within the mastodon-docker directory.
# docker-compose up -d
Creating network "mastodon-docker_internal_network" with the default driver
Creating network "mastodon-docker_external_network" with the default driver
Creating mastodon-docker_es_1 ... done
Creating mastodon-docker_redis_1 ... done
Creating mastodon-docker_db_1 ... done
Creating mastodon-docker_sidekiq_1 ... done
Creating mastodon-docker_web_1 ... done
Creating mastodon-docker_streaming_1 ... done
You can now see all the containers running with docker ps which should look something like the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
a67a26fa2b61 tootsuite/mastodon "/sbin/tini -- yarn …" 25 minutes ago Restarting (1) 47 seconds ago
9b4e6e983c9f tootsuite/mastodon "/sbin/tini -- bundl…" 25 minutes ago Up 25 minutes 3000/tcp, 4000/tcp
52703303a5fd tootsuite/mastodon:v2.5.2 "/sbin/tini -- bash …" 25 minutes ago Up 25 minutes 127.0.0.1:3000->3000/tcp, 4000/tcp
4f4db81e212b redis:4.0-alpine "docker-entrypoint.s…" 3 hours ago Up 3 hours
9887bcc98d49 docker.elastic.co/elasticsearch/elasticsearch-oss:6.1.3 "/usr/local/bin/dock…" 3 hours ago Restarting (1) 59 seconds ago
63824265d55c postgres:9.6-alpine "docker-entrypoint.s…" 3 hours ago Up 3 hours
Connecting with Nginx
Now that we have a running Mastodon instance in a container, we need to connect it to our web-server outside the container. This simply involves creating an appropriate server block to connect request to our Mastodon domain to the ports exposed by the container. I'm basing my server block on this page of the official documentation, see also this excellent guide by Dave Lane.