Skip to content

Instantly share code, notes, and snippets.

@pikesley
Last active December 20, 2022 22:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pikesley/f573e283d7c3724f7cb202e73e0f49ee to your computer and use it in GitHub Desktop.
Save pikesley/f573e283d7c3724f7cb202e73e0f49ee to your computer and use it in GitHub Desktop.
Local Mastodon with `docker-compose`

!!! THIS NO LONGER WORKS, FUCK'S SAKE MASTODON !!!

Clone, patch, build containers

git clone https://github.com/mastodon/mastodon
cd mastodon
{ curl https://gist.githubusercontent.com/pikesley/f573e283d7c3724f7cb202e73e0f49ee/raw/4d25875d725ecc280ff671a3e5317308568d8d1c/hack.patch ; echo ; } | git apply -v --index # apply my patch
touch .env.production
docker compose build
  • the patch allows localhost to hit the server, and disables force_ssl

Setup and migrations

docker-compose run --rm -e DISABLE_DATABASE_ENVIRONMENT_CHECK=1 web bundle exec rake mastodon:setup
  • THIS SPITS OUT A BUNCH OF CONFIG PARTWAY-THROUGH AND TELLS YOU TO WRITE IT TO .env.production, IT DOESN'T SAVE IT FOR YOU LIKE I ASSUMED IT HAD
  • it fails at "Creating admin user" with some complaints about not being able to connect to Redis on localhost ¯\_(ツ)_/¯
  • HOWEVER if you run it again, it works
  • it's all so, so ugly

Run it

docker compose up

Now you should be able to hit it at http://locahost:3000

diff --git a/config/environments/production.rb b/config/environments/production.rb
index 5ea9ea9ba..de1fa82f2 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -44,7 +44,8 @@ Rails.application.configure do
# Allow to specify public IP of reverse proxy if it's needed
config.action_dispatch.trusted_proxies = ENV['TRUSTED_PROXY_IP'].split(/(?:\s*,\s*|\s+)/).map { |item| IPAddr.new(item) } if ENV['TRUSTED_PROXY_IP'].present?
- config.force_ssl = true
+ config.hosts << "localhost"
+ config.force_ssl = false
config.ssl_options = {
redirect: {
exclude: -> request { request.path.start_with?('/health') || request.headers["Host"].end_with?('.onion') || request.headers["Host"].end_with?('.i2p') }
@dominicsayers
Copy link

I had to touch .env.production before the first docker compose build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment