The project now includes a Dockerfile
and a docker-compose.yml
file (which requires at least docker-compose version 1.10.0
).
- Working basic (Linux) server with Nginx (or Apache2; not officially supported).
- Recent stable version of Docker.
- Recent stable version of Docker-compose.
Clone Mastodon's repository.
# Clone mastodon to ~/live directory
git clone https://github.com/tootsuite/mastodon.git live
# Change directory to ~/live
cd ~/live
# Checkout to the latest stable branch
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
Review the settings in docker-compose.yml
. Note that it is not default to store the postgresql database and redis databases in a persistent storage location. If you plan on running your instance in production, you must uncomment the volumes
directive in docker-compose.yml
.
If you're not making any local code changes or customizations on your instance, you can use a prebuilt Docker image to avoid the time and resource consumption of a build. Images are available from Docker Hub: https://hub.docker.com/r/tootsuite/mastodon/
To use the prebuilt images:
- Open
docker-compose.yml
in your favorite text editor.- Comment out the
build: .
lines for all images (web, streaming, sidekiq). - Edit the
image: tootsuite/mastodon
lines for all images to include the release you want. The default islatest
which is the most recent stable version, however it recommended to explicitly pin a version: If you wanted to use v2.2.0 for example, you would edit the lines to say:image: tootsuite/mastodon:v2.2.0
- Save the file and exit the text editor.
- Comment out the
- Run
cp .env.production.sample .env.production
to bootstrap the configuration. You will need to edit this file later. - Run
docker-compose build
. It will now pull the correct image from Docker Hub. - Set correct file-owner with
chown -R 991:991 public
You must build your own image if you've made any code modifications. To build your own image:
- Open
docker-compose.yml
in your favorite text editor.- Uncomment the
build: .
lines for all images (web, streaming, sidekiq) if needed. - Save the file and exit the text editor.
- Uncomment the
- Run
cp .env.production.sample .env.production
to bootstrap the configuration. You will need to edit this file later. - Run
docker-compose build
. - Set correct file-owner with
chown -R 991:991 public
Now the image can be used to generate a configuration with:
docker-compose run --rm web bundle exec rake mastodon:setup
This is an interactive wizard that will guide you through the basic and necessary options and generate new app secrets. At some point it will output your configuration, copy and paste that configuration into the .env.production
file.
The wizard will setup the database schema and precompile assets. After it's done, you can launch Mastodon with:
docker-compose up -d
Following that, make sure that you read the production guide, beginning with the section that describes how to point Nginx to Mastodon.
The container has two volumes, for the assets and for user uploads, and optionally two more, for the postgresql and redis databases.
The default docker-compose.yml maps them to the repository's public/assets
and public/system
directories, you may wish to put them somewhere else. Likewise, the PostgreSQL and Redis images have data containers that you may wish to map somewhere where you know how to find them and back them up.
Note: The --rm
option for docker-compose will remove the container that is created to run a one-off command after it completes. As data is stored in volumes it is not affected by that container clean-up.
Running any of these tasks via docker-compose would look like this:
docker-compose run --rm web bundle exec rake mastodon:media:clear
This approach makes updating to the latest version a real breeze.
git fetch
to download updates from the repository.- Now you need to tell git to use those updates. You have probably changed your
docker-compose.yml
file. Check withgit status
.
- If the
docker-compose.yml
file is modified, rungit stash
to stash your changes.
git checkout TAG_NAME
to use the tag code. (If you have committed changes, usegit merge TAG_NAME
instead, though this isn't likely.)- Only if you ran
git stash
, now rungit stash pop
to redo your changes todocker-compose.yml
. Double check the contents of this file. - Build the updated Mastodon image.
- If you are using a prebuilt image: First, edit the
image: tootsuite/mastodon
lines indocker-compose.yml
to include the tag for the new version. E.g.image: tootsuite/mastodon:v2.3.0
- To pull the prebuilt image, or build your own from the updated code:
docker-compose build
- (optional)
docker-compose run --rm web bundle exec rake db:migrate
to perform database migrations. Does nothing if your database is up to date. - (optional)
docker-compose run --rm web bundle exec rake assets:precompile
to compile new JS and CSS assets. - Follow any other special instructions in the release notes.
docker-compose up -d
to re-create (restart) containers and pick up the changes.