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/ember-cli

…その後、ブラウザでhttp://localhost:4200を開くと、Discourseが表示されるはずです。

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

Docker開発フローは、plugins/ディレクトリ内のシンボリックリンクをサポートしていますが、次の注意事項があります。

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

d/shutdown_dev; d/boot_dev

メモ:

  • Eメールをテストするには、MailHogを実行します:

    d/mailhog
    
  • Gemが見つからない場合は、次を実行します。

    d/bundle install
    
  • DBマイグレーションが必要な場合:

    d/rake db:migrate RAILS_ENV=development
    
  • 終了したら、コンテナを停止できます。

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

    sudo rm -fr data
    
  • permission denied while trying to connect to 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 developement environment setup
Discourse on local pc
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
How to Install Discourse on LocalHost in Windows?
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
Install Discourse Docker on Ubuntu 11
Backup restore failing on clean dev docker env: FATAL: Peer authentication failed for user “postgres”
Install Discourse on macOS for development
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'
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
'Arrive at topic' info missing from email when re-sending invites
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
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
Installing discourse follow plugin in development (boot_dev) setup — no app.yml file
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
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
Migrate a phpBB3 forum to Discourse
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)

This is really easy to get set up! Thanks.

I’m surprised, however, by how slow the local installation is. Is there a way to adjust the container specs somehow? I’d expect a slowdown, but maybe not one so dramatic…

Thanks again.

「いいね!」 7

Windows 10 で Docker を使おうとしており、ガイドについて質問があります。Docker はインストール済みで、Ubuntu コンテナ(中に何もインストールされていない状態)を実行することはできます。この Docker ガイドでは次にリポジトリをクローンするよう書かれていますが、コンテナ内に git がインストールされていないため実行できません。

この時点で、Ubuntu ガイドに従ってコンテナ内ですべての前提条件をインストールすべきでしょうか?それとも、Github で参照されている discourse_dev イメージを使用すべきでしょうか?このガイドは多くの手順を飛ばしているように思えますが、Docker を使ったことがないため、何か見落としているのかもしれません。

「いいね!」 4

おそらく、コンテナ内でリポジトリのクローンを行おうとしているのが原因ではないでしょうか。git clone はローカルマシンで実行する必要があります。すでにローカルに git がインストールされているなら、あとは動作するまであと一歩です。

「いいね!」 3

最初にそれをやったので、それは良いことです。つまり、ローカルマシンにリポジトリのコピーがすでにあります。

Docker コンテナからホストファイルシステムに自動的にアクセスできますか?d/boot_dev --initについて少し混乱していました。d/ の部分が何なのか分からなかったからです(例えば、リポジトリ内に d という名前のフォルダは見当たりませんが、boot_dev は見られます)。

「いいね!」 3

dはリポジトリにあります(さらに下にスクロールしてください)——これはフォルダではなく、bin/dockerへのシンボリックリンクです。git cloneを実行すれば取得できます。

私はこの設定を本格的に使用したことはありませんが、理解している限りでは、ホストファイルシステム(今チェックアウトしたもの)内のソースファイルを直接編集し、Dockerコンテナがそれをマウントして実行する仕組みです。d/*スクリプトが、Docker設定の大部分を自動的に処理してくれます。

「いいね!」 6

ありがとうございます。フォルダ以降を確認するなんて思いもよりませんでした。これで再度取り組むのに十分な情報が揃ったと思います。

「いいね!」 3

まだ何か間違っているようです。このトピック、こちら、そしてこちらのどこを見ても、実行すべき docker コマンドが明記されていません。私は docker run -ti -v LocalRepoPath:/src discourse/discourse_dev を採用し、これで多くのものが初期化され、リポジトリが /src にマウントされたように見えました。しかし、なぜか d/boot_dev --init が実行できません。リポジトリのトップレベルディレクトリで ls を実行するだけで、以下のようなエラーが出ます:

ls: cannot access 'adminjs': Input/output error
ls: cannot access 'd': Input/output error
ls: cannot access 'jsapp': Input/output error

何かご存知の方がいらっしゃいますか?

「いいね!」 3

これを複雑にしすぎているかもしれません。最初の投稿にあるチュートリアルには、始めるために必要なものがすべて含まれています。

d/* コマンドは、あなたが手動で行う必要がないように、すべての Docker コマンドの魔法を代行してくれます。リポジトリをクローンした後、ホストマシンで d/boot_dev --initd/unicorn コマンドを実行すれば、http://localhost:9292 が動作するようになるはずです。これらのスクリプトは Docker を呼び出してコンテナを生成し、起動します。d/shutdown_dev で停止できます。

ホスト上のリポジトリファイルを閲覧している際にこれらのエラーが発生している場合、ファイルシステムに何らかの問題があるようです。ディスク容量が不足していないでしょうか?

「いいね!」 4

ため息、なるほど。それらは Docker 内で実行する必要があると思っていたのですが。とは言え、d/boot_dev --init は Windows の PowerShell ではどうやら動作しないようです(そのため、この Docker ガイドでは Mac と Ubuntu ホストのみが言及されているのでしょう)。Linux サブシステム(v1)でコマンドを実行しようとしましたが、もちろん Docker ステップで失敗しました。Docker は Linux サブシステムではなく Windows にインストールしていたためです。


次に、Windows 用の Git Bash で実行しようとしました。d/boot_dev --init は実行できませんでした(エラー:“d/boot_dev: Is a directory”)が、bin/docker/boot_dev --init は実行できました。これで多くのプル処理が進みましたが、その後以下のエラーで失敗しました。

C:\Program Files\Docker\Docker\resources\bin\docker.exe: Error response from daemon: Mount denied:
The source path “PathToRepo/data/postgres;C”
doesn’t exist and is not known to Docker.

このエラーは、以下の Stack Overflow の記事に従ってマウントパスをエスケープすることで回避できたと思います(おそらく):
https://stackoverflow.com/questions/50608301/docker-mounted-volume-adds-c-to-end-of-windows-path-when-translating-from-linux

その後、次のエラーが発生しました:

C:\Program Files\Docker\Docker\resources\bin\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused “exec: "C:/Program Files/Git/sbin/boot": stat C:/Program Files/Git/sbin/boot: no such file or directory”: unknown.

C:/Program Files/Git/sbin/boot は私のファイルシステムに存在しないため、このエラーは驚きではありません。boot_dev ファイル内で sbin/boot に言及しているのは、Docker コマンドのこの部分だけです:discourse/discourse_dev:release /sbin/boot

現状はほぼここが限界です… 次は何を試せばいいかよくわかりません。

「いいね!」 3

申し訳ありませんが、Windows のことは詳しくないため、これ以上お手伝いすることができません。

@rishabh さんに、Windows でも動作するはずかどうかを確認し、そのための不足している手順を追記するか(動作しない場合はその旨を注記するか)、更新していただけないでしょうか。

「いいね!」 3

@sam 開発用として Discourse を実行する際、私が行おうとしている方法は、まともなサポート対象のやり方なのでしょうか?Windows 開発スレッド で、あなたがこの方法を試したと述べられていましたが、現時点ではうまくいっていません。基本的な(Discourse 以外の)Ubuntu コンテナは技術的には動作しますが、このスレッドの OP に記載されている特定のコマンドは機能しません。

あなたは以前、私に対して以下のように述べられました:

したがって、Windows 上の Docker で直面している問題を解決するための代替案がない限り、損失を最小限に抑えるためにも、Virtual Box などのツールを使って Ubuntu VM 上で実行する方がよいでしょう。

「いいね!」 2

私たちの多くは、ゼロの問題でスローリングを使用しています。ゲームも動作し、Steamも動作し、すべてが問題なく動作します。

ここで不安を感じることは理解できますが、実際には大きな問題ではありません。とにかく、これがあなたにとってあまりにも怖い場合は、Hyper-VやVirtualBoxのような従来のVMを使用することをお勧めします。そこにDockerをインストールし、Docker開発セットアップを使用してください。

「いいね!」 6

これが私のメイン(かつ唯一の)コンピューターでなければ、スローリングに参加するところですが、リスクを冒すことはできません。そのため、Docker を使った従来の VM にします。アドバイスありがとうございます。まもなく何かしらの環境を構築して運用できることを願っています。

VM に割り当てるディスク容量と RAM はどれくらいが適切でしょうか?ディスク容量は 16GB、RAM は 4GB くらいを考えていましたが、まず確認したくて質問しました。

「いいね!」 1

おそらくそれで十分でしょう。理想的なレシピを見つけるには、試行錯誤するのが一番です。

「いいね!」 6

よし、これで実際に動くところまで来ました。Ubuntu VM 内で Docker を使ってローカルインスタンスを起動しています。d/boot_dev --init は初回のみ実行し、その後は d/boot_dev を実行するだけで良いと推測しているのですが、合っていますか?質問した理由は、d/unicorn--init を含めると動作する一方、d/boot_dev から --init を省略すると動作しないためです。起動に失敗すると、以下のエラーが表示されます。

Could not find aws-partitions-1.270.0 in any of the sources.
Run bundle install to install missing gems.

しかし、その後 bundle install を実行すると、以下のエラーで失敗します。

actionview_precompiler-0.2.2 requires ruby version >= 2.6, which is incompatible with the current version, ruby 2.5.1p57

特定の Ruby バージョンに更新すべきでしょうか?それとも他に何か問題があるのでしょうか?


私の VM は Ubuntu 18.04 (LTS) です。今回は OP の手順をそのまま追うことができました。どこで間違ったのか(もし間違った箇所があるなら)わかりません。

「いいね!」 2

bundle installを使うのではなく、d/bundle installを使用してください。コンテナ内でバンドルをインストールしたい場合、VM に Ruby は必要ありません。

「いいね!」 4

ええ、そのように感じていました。コンテナ内で実行する正しい方法がわからなかっただけです。またお手伝いいただき、ありがとうございます!

「いいね!」 2

最新のバージョンのレポジトリをプルしましたが、いつものように d/unicorn が「不足しているガムをインストールするには bundle install を実行してください」と表示されます。しかし、今回は d/bundle install を実行すると、以下のようなエラーが発生します:

Fetching source index from https://rubygems.org/

Retrying fetcher due to error (2/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/

Retrying fetcher due to error (3/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/

Retrying fetcher due to error (4/4): Bundler::HTTPError Could not fetch specs from https://rubygems.org/

Could not fetch specs from https://rubygems.org/

そのため、現在 Discourse を実行することができません。この問題がプル(直接的または間接的)に関連しているのか、それとも全く無関係なのかはわかりません。このエラーを検索しても特に役立つ情報は得られず、次にどう進めばよいか見当がつかない状況です。

「いいね!」 1

rubygems.org にアクセスできましたか?

「いいね!」 1