Docker環境でMastodonをインストールしてみました。
Mastodonについては下記の記事が参考になりました。
gnusocial や mastodon の哲学
https://blog.cardina1.red/2017/04/13/federated-social-web/
環境
・CentOS Linux release 7.3.1611 (Core)
・Kernel: 3.10.0-514.16.1.el7.x86_64
・Docker version 17.03.1-ce, build c6d412e
・docker-compose version 1.12.0, build b31ff33
・Mastodon v1.2.2
Mastodon
https://github.com/tootsuite/mastodon
documentation/Running-Mastodon/Docker-Guide.md
https://github.com/tootsuite/documentation/blob/master/Running-Mastodon/Docker-Guide.md
DockerでMastodonをローカルで動かしてみた! ので、その方法をご紹介
https://ai-create.net/magazine/2017/04/15/mastodonをdockerでローカルに構築してみた!-ので、その方/
- mastodonのダウンロード
- 環境設定ファイルの準備
- docker-compose.ymlの編集
- mastodonイメージのビルド
- PAPERCLIP_SECRETの生成
- SECRET_KEY_BASEの生成
- OTP_SECRETの生成
- データベースの作成
- アセットのプリコンパイル
- Mastodonの起動
- mastodonにアクセス
- ユーザー登録
- mastodonにログイン
- mastodonサイト設定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ git clone https://github.com/tootsuite/mastodon.git Cloning into 'mastodon'... remote: Counting objects: 29013, done. remote: Compressing objects: 100% (6/6), done. remote: Total 29013 (delta 1), reused 1 (delta 1), pack-reused 29006 Receiving objects: 100% (29013/29013), 35.17 MiB | 3.29 MiB/s, done. Resolving deltas: 100% (17718/17718), done. $ cd mastodon $ ls -a . .env.production.sample .nvmrc Capfile README.md config.ru public .. .env.test .rspec Dockerfile Rakefile db scalingo.json .babelrc .env.vagrant .rubocop.yml Gemfile Vagrantfile docker-compose.yml spec .buildpacks .eslintignore .ruby-version Gemfile.lock app docs storybook .codeclimate.yml .eslintrc.json .slugignore ISSUE_TEMPLATE.md app.json lib streaming .dockerignore .git .travis.yml LICENSE bin log vendor .editorconfig .gitignore CONTRIBUTING.md Procfile config package.json yarn.lock |
1 |
$ cp .env.production.sample .env.production |
デフォルト設定です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
$ cat .env.production # Service dependencies REDIS_HOST=redis REDIS_PORT=6379 # REDIS_DB=0 DB_HOST=db DB_USER=postgres DB_NAME=postgres DB_PASS= DB_PORT=5432 # Federation LOCAL_DOMAIN=example.com LOCAL_HTTPS=true # Use this only if you need to run mastodon on a different domain than the one used for federation. # Do not use this unless you know exactly what you are doing. # WEB_DOMAIN=mastodon.example.com # Application secrets # Generate each with the `rake secret` task (`docker-compose run --rm web rake secret` if you use docker compose) PAPERCLIP_SECRET= SECRET_KEY_BASE= OTP_SECRET= # Registrations # Single user mode will disable registrations and redirect frontpage to the first profile # SINGLE_USER_MODE=true # Prevent registrations with following e-mail domains # EMAIL_DOMAIN_BLACKLIST=example1.com|example2.de|etc # Only allow registrations with the following e-mail domains # EMAIL_DOMAIN_WHITELIST=example1.com|example2.de|etc # Optionally change default language # DEFAULT_LOCALE=de # E-mail configuration # Note: Mailgun and SparkPost (https://sparkpo.st/smtp) each have good free tiers # If you want to use an SMTP server without authentication (e.g local Postfix relay) # then set SMTP_AUTH_METHOD to 'none' and *comment* SMTP_LOGIN and SMTP_PASSWORD. # Leaving them blank is not enough for authentication method 'none'. SMTP_SERVER=smtp.mailgun.org SMTP_PORT=587 SMTP_LOGIN= SMTP_PASSWORD= SMTP_FROM_ADDRESS=notifications@example.com #SMTP_DOMAIN= # defaults to LOCAL_DOMAIN #SMTP_DELIVERY_METHOD=smtp # delivery method can also be sendmail #SMTP_AUTH_METHOD=plain #SMTP_OPENSSL_VERIFY_MODE=peer #SMTP_ENABLE_STARTTLS_AUTO=true # Optional user upload path and URL (images, avatars). Default is :rails_root/public/system. If you set this variable, you are responsible for making your HTTP server (eg. nginx) serve these files. # PAPERCLIP_ROOT_PATH=/var/lib/mastodon/public-system # PAPERCLIP_ROOT_URL=/system # Optional asset host for multi-server setups # CDN_HOST=assets.example.com # S3 (optional) # S3_ENABLED=true # S3_BUCKET= # AWS_ACCESS_KEY_ID= # AWS_SECRET_ACCESS_KEY= # S3_REGION= # S3_PROTOCOL=http # S3_HOSTNAME=192.168.1.123:9000 # S3 (Minio Config (optional) Please check Minio instance for details) # S3_ENABLED=true # S3_BUCKET= # AWS_ACCESS_KEY_ID= # AWS_SECRET_ACCESS_KEY= # S3_REGION= # S3_PROTOCOL=https # S3_HOSTNAME= # S3_ENDPOINT= # S3_SIGNATURE_VERSION= # Optional alias for S3 if you want to use Cloudfront or Cloudflare in front # S3_CLOUDFRONT_HOST= # Streaming API integration # STREAMING_API_BASE_URL= # Advanced settings # If you need to use pgBouncer, you need to disable prepared statements: # PREPARED_STATEMENTS=false # Cluster number setting for streaming API server. # If you comment out following line, cluster number will be `numOfCpuCores - 1`. STREAMING_CLUSTER_NUM=1 |
取り敢えず下記の部分だけ変更しました。
LOCAL_DOMAIN=mastodon.rootlinks.net
LOCAL_HTTPS=false
DEFAULT_LOCALE=ja
mastodonのデータを外部に保存する場合はvolumes directiveのコメントを外します。取り敢えず動かすならコンテナ内で保存でもいいと思いますが。
デフォルト設定です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
$ cat docker-compose.yml version: '2' services: db: restart: always image: postgres:alpine ### Uncomment to enable DB persistance # volumes: # - ./postgres:/var/lib/postgresql/data redis: restart: always image: redis:alpine ### Uncomment to enable REDIS persistance # volumes: # - ./redis:/data web: restart: always build: . image: gargron/mastodon env_file: .env.production command: bundle exec rails s -p 3000 -b '0.0.0.0' ports: - "3000:3000" depends_on: - db - redis volumes: - ./public/assets:/mastodon/public/assets - ./public/system:/mastodon/public/system streaming: restart: always build: . image: gargron/mastodon env_file: .env.production command: npm run start ports: - "4000:4000" depends_on: - db - redis sidekiq: restart: always build: . image: gargron/mastodon env_file: .env.production command: bundle exec sidekiq -q default -q mailers -q pull -q push depends_on: - db - redis volumes: - ./public/system:/mastodon/public/system |
アンコメントしたディレクトリは構築時に自動で作成されます。
本運用する場合は/var/lib/mastodonなどを作成してこれを指定した方がいいですね。
1 2 |
drwx------ 19 70 root 4096 4月 26 15:39 postgres drwxr-xr-x 2 100 root 21 4月 26 18:20 redis |
そこそこ時間が掛かります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ docker-compose build redis uses an image, skipping db uses an image, skipping Building streaming Step 1/9 : FROM ruby:2.4.1-alpine 2.4.1-alpine: Pulling from library/ruby 709515475419: Pull complete 7fb3cefb04d0: Pull complete 90b9c8a10de7: Pull complete 6b7eca1d4c36: Pull complete 34fa769a4a3d: Pull complete (snip) Step 9/9 : VOLUME /mastodon/public/system /mastodon/public/assets ---> Using cache ---> c689dc374324 Successfully built c689dc374324 |
いくつかwarningが発生しましたがイメージができました。
1 2 3 |
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE gargron/mastodon latest c689dc374324 17 seconds ago 684 MB |
最後の行の cb55583db0c990….. の部分を.env.productionのPAPERCLIP_SECRET= に記述します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$ docker-compose run --rm web rake secret Creating network "mastodon_default" with the default driver Pulling redis (redis:alpine)... alpine: Pulling from library/redis 627beaf3eaaf: Pull complete a503a4771a4a: Pull complete 72c5d910c683: Pull complete 6aadd3a49c30: Pull complete adf925aa1ad1: Pull complete 0565da0f872e: Pull complete Digest: sha256:9cd405cd1ec1410eaab064a1383d0d8854d1eef74a54e1e4a92fb.......... Status: Downloaded newer image for redis:alpine Pulling db (postgres:alpine)... alpine: Pulling from library/postgres 627beaf3eaaf: Already exists 2d555ba539f4: Pull complete f829d456f997: Pull complete 0ed44e989a3a: Pull complete 64960f1d9c23: Pull complete 299245faa0f0: Pull complete a0b381a833e6: Pull complete bacfe251908e: Pull complete Digest: sha256:b2eb0b1194dfc7a42d496fc2c333ffad8c38e552a0d5411450c7b3.......... Status: Downloaded newer image for postgres:alpine Creating mastodon_redis_1 Creating mastodon_db_1 cb55583db0c99009bebf2d65939d1fa4d7c3592a1c661d0ee9054afaa511e4c05d937f4642b1ddf6f93965d86a1654acb1c8398086a5f48c1d4a04.......... |
同様にSECRET_KEY_BASEの生成を行い.env.productionのSECRET_KEY_BASE= に記述します。
1 2 |
$ docker-compose run --rm web rake secret 9ed614579fb75dd1616054490216cab4d0f6d47ea6bd6a77a3b45fba22e3629d5ec1dfdc9eb2e24687e868229f6999d6d2b447887c660f668efaec.......... |
最後にOTP_SECRETの生成を行い.env.productionのOTP_SECRET= に記述します。
1 2 |
$ docker-compose run --rm web rake secret ae0c48001e90a99d59a18d240f02363c07e6e69c69383d17fc2dde08fd8c2a0b069581dc0738973bf3ff9d2314068046a2367ed94a6c9c2486ca0d.......... |
1 2 3 4 5 6 7 8 9 10 11 |
$ docker-compose run --rm web rake db:migrate Migrating to CreateAccounts (20160220174730) == 20160220174730 CreateAccounts: migrating =================================== -- create_table(:accounts, {}) -> 0.0064s (snip) Migrating to AddStatusIdIndexToStatusesTags (20170424112722) == 20170424112722 AddStatusIdIndexToStatusesTags: migrating =================== -- add_index(:statuses_tags, :status_id) -> 0.0022s == 20170424112722 AddStatusIdIndexToStatusesTags: migrated (0.0022s) ========== |
1 2 3 4 5 6 |
$ docker-compose run --rm web rake assets:precompile I, [2017-04-25T11:57:05.739686 #1] INFO -- : Writing /mastodon/public/assets/application_public-88cacc5649131f6fe166e225b502561c9566af630bc8b9ac9d1af188d4472642.js I, [2017-04-25T11:57:05.740338 #1] INFO -- : Writing /mastodon/public/assets/application_public-88cacc5649131f6fe166e225b502561c9566af630bc8b9ac9d1af188d4472642.js.gz (snip) I, [2017-04-25T11:58:25.602655 #1] INFO -- : Writing /mastodon/public/assets/pghero/application-9bc22f0902dcd973784cb5dd4a5fd5f7437691f893fe23bef94cfb6ae256059b.css I, [2017-04-25T11:58:25.602821 #1] INFO -- : Writing /mastodon/public/assets/pghero/application-9bc22f0902dcd973784cb5dd4a5fd5f7437691f893fe23bef94cfb6ae256059b.css.gz |
アタッチでの起動
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$ docker-compose up mastodon_redis_1 is up-to-date mastodon_db_1 is up-to-date Creating mastodon_sidekiq_1 Creating mastodon_web_1 Creating mastodon_streaming_1 Attaching to mastodon_redis_1, mastodon_db_1, mastodon_sidekiq_1, mastodon_web_1, mastodon_streaming_1 redis_1 | 1:C 25 Apr 11:46:12.377 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf redis_1 | _._ redis_1 | _.-``__ ''-._ redis_1 | _.-`` `. `_. ''-._ Redis 3.2.8 (00000000/0) 64 bit redis_1 | .-`` .-```. ```\/ _.,_ ''-._ redis_1 | ( ' , .-` | `, ) Running in standalone mode redis_1 | |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 redis_1 | | `-._ `._ / _.-' | PID: 1 redis_1 | `-._ `-._ `-./ _.-' _.-' redis_1 | |`-._`-._ `-.__.-' _.-'_.-'| redis_1 | | `-._`-._ _.-'_.-' | http://redis.io redis_1 | `-._ `-._`-.__.-'_.-' _.-' redis_1 | |`-._`-._ `-.__.-' _.-'_.-'| redis_1 | | `-._`-._ _.-'_.-' | redis_1 | `-._ `-._`-.__.-'_.-' _.-' redis_1 | `-._ `-.__.-' _.-' redis_1 | `-._ _.-' redis_1 | `-.__.-' redis_1 | (snip) |
デタッチでの起動
1 |
$ docker-compose up -d |
http://mastodon.rootlinks.net:3000/にアクセスすると登録画面が表示されます。
DNSなどは適宜設定して下さい。
ユーザー登録を行います。通常は登録したメールアドレスに届いたメールから正式登録作業を行なうようですが、メールの設定をしていないのでコマンドで認証します。
1 2 |
$ docker-compose run --rm web rails mastodon:confirm_email USER_EMAIL=mastodon@mail.address mastodon@mail.address confirmed |
mastodonのサイト設定ができるように管理者の設定も行います。
登録したユーザー名を指定します。
1 2 3 |
$ docker-compose run --rm web rails mastodon:make_admin USERNAME=mastodon Congrats! mastodon is now an admin. \o/ Navigate to http://mastodon.rootlinks.net/admin/settings to get started |
管理者権限のユーザでログインした後にhttp://mastodon_HOST:3000/admin/settingsにアクセスすると設定できます。
取り敢えず立ち上げることができました。