How to Install Mastodon Using Docker on Alibaba Cloud ECS

By Arslan Ud Din Shafiq, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Mastodon is an open source decentralized social network that allows anyone to host their own server node in the network. In this tutorial, I will install and set up Mastodon on Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04.

Prerequisites

  • You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get $300 — $1200 worth in Alibaba Cloud credits for your new account. If you don’t k about how to setup your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 2GB RAM and 2 Core processor.
  • A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
  • Domain name must be pointed to your Alibaba Cloud ECS’s IP address
  • Access to VNC console in your Alibaba Cloud or SSH client installed in your PC
  • Set up your server’s hostname and create user with root privileges.

Setting Up Your Server

Before proceeding with installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with sudo privileges.

Software-properties-common package is required to get the supported files for installation of Docker CE. To install software-properties-common execute the command.

Apt-transport-https, ca-certificates, and curl are required for installation of Docker CE. To install them, execute these commands.

Install Docker CE and Docker Compose

Add GPG key for Docker by executing command below.

Execute the following command to verify the fingerprint of GPG key.

Add the Docker repository by executing the command below.

Update your system by executing command below to load added repository.

Execute the following command to install Docker.

Add your username to docker group by executing command below.

Close your current shell session and start a new session. Otherwise, you won’t be able to run Docker and you may see permission errors.

Execute the following command to check either docker run correctly or not.

To download and install Docker Compose, execute the following command.

To set permissions for Docker Compose file, execute the following command.

Install Mastodon:

Execute the following command to clone Mastodon from Git repository.

Navigate to downloaded directory by running command below.

Execute the following command to copy .env.production.sample to .env.production.

To generate secret keys, you will need to build Docker image and run it. To build it, execute the following command.

The Docker image has been built successfully. You will need to generate 3 secret keys that are required for configuration. To generate SECRET_KEY_BASE, execute the following command.

Execute the following command to insert the value of SECRET_KEY_BASE in .env.production file

To generate OTP_SECRET, execute the following command.

Execute the following command to insert the value of SECRET_KEY_BASE in .env.production file

To generate PAPERCLIP_SECRET, execute the following command.

Execute the following command to insert the value of PAPERCLIP_SECRET in .env.production file

You will need to update the value of LOCAL_DOMAIN. To do so, you will need to open .env.production file in text editor. Execute the following command to open .env.production file.

Find LOCAL_DOMAIN variable and change its value from example.com to your domain name or IP address of ECS and save the updated file.

Navigate to /mastodon

You will need to build the Docker image again because you have made changes above. To build it, execute the following command.

execute the following command to run migrations.

To make things snappier, you will need to pre-compile assets. To do so, execute the following command.

Run the container by executing command below.

Install and Configure Nginx Server

To make Mastodon working by creating Nginx configuration and install SSL certificate, you will require Nginx server to be installed.

Execute the following command to install nginx server.

You will need to remove default site Nginx configuration by executing the command below.

Remove symlink for default site by executing command below.

Create the Nginx configuration file for Mastodon by executing command below.

Create symlink of Mastodon by executing command below.

Execute the following command to open Mastodon Nginx configuration file in nano text editor.

Copy-paste the following text in opened file and save the changes.

Install SSL Certificate:

We will install SSL certificate using Let’s Encrypt with Certbot. To do so, execute the following steps.

Update the package.

Install software-properties-common.

Add the certbot repository by using command below.

Update the package to load the added certbot repository.

Stop apache before issuance of SSL certificate.

Install python-certbot-apache using the command below.

Execute the following command to get Let’s Encrypt SSL issued.

Select the option 2 to redirect the link to https and update virtual host settings for SSL. Restart apache server.

You can access your website at https://your_domain_name.tld

Image for post
Image for post

There you go! You have successfully installed Mastodon on an Alibaba Cloud ECS server. You can secure it by changing the database default password and by setting up an administrator account.

Original Source

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store