Docker を使用して開発環境で Discourse をインストール

Docker での開発

Discourse は Docker 上で動作するため、Discourse 開発用コンテナを使用して、ソースディレクトリから直接 Discourse を実行できます。

:white_check_mark: メリット:システム依存関係のインストールが不要で、開発環境を素早くセットアップするための設定も一切不要です。

:x: デメリット:Ubuntu 上のネイティブ開発環境よりもわずかに遅く、MacOS 上のネイティブインストールよりもはるかに遅くなります。

詳しくは Developing Discourse using a Dev Container をご覧ください。

ステップ 1: Docker のインストール

Ubuntu

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce

19.10

sudo apt-get install docker.io
sudo usermod -a -G docker $USER
sudo reboot

Windows WSL: Ubuntu

上記のコマンドは WSL 内で実行できますが、すべてのファイルを WSL のファイルシステム内に配置している必要があります。例えば、~/discourse 内にあれば問題なく動作しますが、/mnt/c/discourse 内に配置すると失敗します。

MacOS

:warning: Discourse 開発用 Docker イメージは x86_64 アーキテクチャでのみ利用可能です。M1 Mac はアーキテクチャエミュレーションを使用してイメージを起動できますが、QEMU における inotify サポートの欠如のため、Discourse が起動しない可能性が高いです。

その代わりに、Install Discourse on macOS for development をご利用ください

オプション 1: Docker ストアからパッケージ化された .dmg をダウンロードする
オプション 2: brew install docker

ステップ 2: コンテナの起動

Discourse リポジトリをローカルデバイスにクローンします。

git clone https://github.com/discourse/discourse.git
cd discourse

(ソースルートから)

d/boot_dev --init
    # 以下の処理が完了するまでお待ちください:
    #   - 依存関係のインストール
    #   - データベースのマイグレーション
    #   - 管理者ユーザーの作成(対話が必要になります)

# 1 つ目のターミナルで:
d/rails s

# 別のターミナルで
d/dev --only ember

…その後、http://localhost:3000 でブラウザを開くと、さあ、Discourse が表示されます。

プラグインのシンボリックリンク

Docker 開発フローでは plugins/ ディレクトリ配下のシンボリックリンクがサポートされていますが、以下の点にご注意ください:

新しいプラグインのシンボリックリンクを作成するたびに、Docker コンテナを以下のように再起動する必要があります:

d/shutdown_dev; d/boot_dev

注記:

  • メールをテストするには、MailHog を実行してください:

    d/mailhog
    
  • 不足している gem がある場合は、以下を実行してください:

    d/bundle install
    
  • データベースのマイグレーションが必要な場合:

    d/rake db:migrate RAILS_ENV=development
    
  • 作業が完了したら、以下で Docker コンテナを終了させることができます:

    d/shutdown_dev
    
  • データは、ソースルート内の tmp/postgres ディレクトリでコンテナの実行間で永続化されます。何らかの理由でデータベースをリセットしたい場合は、以下を実行してください:

    sudo rm -fr data
    
  • Docker への接続中に権限が拒否されました」というエラーが表示された場合は、以下を実行してください:

    run `sudo usermod -aG docker ${USER}`
    sudo service docker restart
    
  • コンテナのポートをネットワーク全体にグローバルに公開したい場合(デフォルトではオフ)は、以下を使用してください:

    d/boot_dev -p
    
  • Dockerfile は GitHub の discourse/discourse_docker、具体的には image/discourse_dev から提供されています。

テストの実行

d/rake autospec

特定のプラグインのテストを実行するには、以下のような方法も可能です:

d/rake plugin:spec["discourse-follow"]

さらに詳細に指定したい場合は、以下のようにしてください:

my-machine:~/discourse$ d/shell
discourse@discourse:/src$ RAILS_ENV=test /src/bin/rspec plugins/discourse-follow/spec/lib/updater_spec.rb:37

このドキュメントはバージョン管理されています。変更を提案する場合は GitHub 上で行ってください。

「いいね!」 72
Using a launcher built docker image in docker-compose
IDE and comfortable DEV environment for newbies
Docker install on MacOS
How to install Discourse locally?
Installing Discourse for macOS Development Using asdf and docker-compose
Discourse on local pc
Discourse developement environment setup
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
Install Discourse Docker on Ubuntu 11
Unicode (Russian) username validation fails randomly
Qunit in Docker
Is it possible to use a local plugin directory with a docker install?
Is it possible to use a local plugin directory with a docker install?
Problem with development on Windows with Docker and mounted volume
[Resolved] Recent change breaks connectivity in Docker (+ non-Docker)
How might we better structure #howto?
Apple M1 for discourse development
How to open via internal IP?
Fast, efficient plugin development with Docker dev install (Windows WSL2)
How do I install a stable version of Discourse on Docker locally?
Backup fails on localhost with docker
How do I install a stable version of Discourse on Docker locally?
Problems with understanding the development of Discourse
Need to create custom static page as home page
Docker new licensing
Backup restore failing on clean dev docker env: FATAL: Peer authentication failed for user “postgres”
Can't build Discourse on Ubuntu 20.10
Installing discourse for development is failing
Create, download, and restore a backup of your Discourse database
Set up a local Discourse Development Environment?
How do you install Discourse using Windows 10 Docker Desktop?
NoMethodError: undefined method `min_tags_from_required_group'
Migrate a phpBB3 forum to Discourse
Install plugins in your non-Docker development environment
NoMethodError: undefined method `min_tags_from_required_group'
Error installing `bullseye-backports` when trying to install for Development
What I should do for migration from Cusdis to Discourse
Migrate a MyBB forum to Discourse
Local installation internal use only
Maintaining an up-to-date development environment
PG::UndefinedTable: ERROR: relation "pg_range" does not exist
Docker-compose.yml to run discourse locally
Allow subscription of predetermined length
Cannot load any images “Uncaught (in promise) no-response: no-response”
Discovery document is missing
What are the benefits of a dev environment?
Installing Discourse on windows using Docker Desktop
Installing discourse follow plugin in development (boot_dev) setup — no app.yml file
How to troubleshoot database errors in an outdated plugin?
Error when building: discourse does not support compiling scss/sass files via sprockets
Integration into custom auth system where emails are not unique?
Installer un environnement developpement discourse sur windows
Contributing to Discourse development
Install Discourse on Ubuntu or Debian for Development
There was an error while trying to write to `/src/Gemfile.lock`. It is likely that you need to grant write permissions for that path
Tags rearranged, triggering an extra edit
Ember addons are resolving as incorrect peer dependencies. -- fixed by removing "content-tag@3.1.0": "patches/content-tag@3.1.0.patch",
Trying to install Discourse on portainer but it's not pulling the base container
Developing Discourse using a Dev Container
Subscribe to post an ad
Postgres doesn't seem to be running when running Discourse locally using Docker
Discourse OpenID Connect (OIDC)
How can I install Discourse on Windows? Getting restarting (100) error
Dev environment: recommended way to bootstrap the first admin account without email?
Dev environment: recommended way to bootstrap the first admin account without email?
Total newbie struggling to preview the signup modal with my test theme, what am I missing?
Configure Discourse to use a separate PostgreSQL server
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
'Arrive at topic' info missing from email when re-sending invites
Developing Discourse using a Dev Container
Discourse API developers docker-compose basic image
Which is the better option to self-host?
Using a launcher built docker image in docker-compose
Without any coding knowledge, is it possible to install and maintain Discourse?
I want to install a plugin for development, what should I do?
Can't uninstall on Ubuntu 18.04
Install Discourse on macOS for development
Developing Discourse using a Dev Container
Using a launcher built docker image in docker-compose
Bundle install fails after adding gem "mysql2" and gem "reverse_markdown"
Issue in setup discourse on ubuntu server
`script/osx_dev` script is pretty broken
Can't set up dev environment due to cppjieba_rb failing to install
I want to install a plugin for development, what should I do?
Stuck in infinite loop in Mac terminal after source ~/.bashrc
Install on macOS – Failure: Scheduler::Defer can pause and resume
Install on macOS – Failure: Scheduler::Defer can pause and resume
Install Discourse for Development using Docker is Failed
OAuth2 and Microsoft ADFS
Availability of OpenID Connect in hosted plans
Can't set up dev environment due to cppjieba_rb failing to install
Adding command line tools support for user api keys
Adding command line tools support for user api keys
Discourse redirects to the OAuth server after loading `/?authComplete=true`
Hello from Gitpod! (installing on google cloud + automated dev setup)
How to Install Discourse on LocalHost in Windows?