Install Discourse for development using Docker

Developing using Docker

Since Discourse runs in Docker, you should be able to run Discourse directly from your source directory using a Discourse development container.

:white_check_mark: Pros: No need to install any system dependencies, no configuration needed at all for setting up a development environment quickly.

:x: Cons: Will be slightly slower than the native dev environment on Ubuntu, and much slower than a native install on MacOS.

See also Developing Discourse using a Dev Container

Step 1: Install 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

You can run the above commands within WSL but you must have all the files inside WSL file system. E.g. it works just fine if it’s inside ~/discourse but it fails if it’s placed inside /mnt/c/discourse.

MacOS

:warning: The Discourse development docker image is only available for x86_64 architectures. M1 Macs are capable of starting the image using architecture emulation, but Discourse is unlikely to boot due to the lack of inotify support in QEMU.

Instead, you should use Install Discourse on macOS for development

Option 1: Download a packaged .dmg from the Docker store
Option 2: brew install docker

Step 2: Start Container

Clone Discourse repository to your local device.

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

(from your source root)

d/boot_dev --init
    # wait while:
    #   - dependencies are installed,
    #   - the database is migrated, and
    #   - an admin user is created (you'll need to interact with this)

# In one terminal:
d/rails s

# And in a separate terminal
d/dev --only ember

…then open a browser on http://localhost:3000 and voila!, you should see Discourse.

Plugin Symlinks

The Docker development flow supports symlinks under the plugins/ directory, with the following caveat:

Whenever a new plugin symlink is created, the Docker container must be restarted with:

d/shutdown_dev; d/boot_dev

Notes:

  • To test emails, run MailHog :

    d/mailhog
    
  • If there are missing gems, run:

    d/bundle install
    
  • If a db migration is needed:

    d/rake db:migrate RAILS_ENV=development
    
  • When you’re done, you can choose to kill the Docker container with:

    d/shutdown_dev
    
  • Data is persisted between invocations of the container in your source root tmp/postgres directory. If for any reason you want to reset your database run:

    sudo rm -fr data
    
  • If you see errors like “permission denied while trying to connect to Docker”, Run:

    run `sudo usermod -aG docker ${USER}`
    sudo service docker restart
    
  • If you wish to globally expose the ports from the container to the network (default off) use:

    d/boot_dev -p
    
  • The Dockerfile comes from discourse/discourse_docker on GitHub, in particular image/discourse_dev.

Running Tests

d/rake autospec

To run specific plugin tests, you can also do something like this:

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

Or even something like this to be even more specific:

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

This document is version controlled - suggest changes on github.

73개의 좋아요
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
Install Discourse Docker on Ubuntu 11
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
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
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
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
Developing Discourse using a Dev Container
'Arrive at topic' info missing from email when re-sending invites
Automatically updating themes and plugins to .gjs file format
Integration into custom auth system where emails are not unique?
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?

설치가 정말 쉬웠습니다! 감사합니다.

다만, 로컬 설치 속도가 생각보다 느려서 놀랐습니다. 컨테이너 사양을 어떻게든 조정할 수 있는 방법이 있을까요? 속도가 느려질 수는 있겠지만, 이 정도까지 빠를 줄은 몰랐거든요…

다시 한번 감사합니다.

7개의 좋아요

Windows 10에서 Docker를 사용하려고 하는데, 가이드에 대해 질문이 있습니다. Docker는 설치되어 있고, 컨테이너를 실행할 수 있습니다(컨테이너에는 기본적으로 거의 아무것도 설치되어 있지 않은 상태). 이 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을 실행하면 이 파일도 함께 가져올 수 있습니다.

저는 이 설정을 광범위하게 사용해 본 적은 없지만, 제 이해로는 호스트 파일시스템(방금 체크아웃한 곳)에서 소스 파일을 직접 편집하고, 도커 컨테이너가 해당 파일을 마운트하여 그 위에서 실행하는 방식입니다. d/* 스크립트가 도커 설정 작업의 대부분을 대신해 줍니다.

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/* 명령어는 도커 명령어의 마법을 대신 수행해 주므로, 사용자가 직접 할 필요가 없습니다. 리포지토리를 클론한 후, 호스트 머신에서 d/boot_dev --init와 d/unicorn 명령어를 실행하면 http://localhost:9292가 작동하도록 하는 데 필요한 모든 것이 완료됩니다. 이 스크립트들은 도커를 호출하여 컨테이너를 생성하고 시작해 줍니다. d/shutdown_dev는 이를 중지합니다.

호스트에서 리포지토리 파일을 탐색하는 동안 해당 오류가 발생한다면, 파일 시스템에 다른 문제가 있는 것 같습니다. 디스크 공간이 부족했던 것은 아닌가요?

4개의 좋아요

한숨, 알겠습니다. 그 명령어들이 docker 안에서 실행되어야 한다고 생각했거든요. 그런데 d/boot_dev --init는 Windows의 Powershell에서는 작동하지 않는 것 같습니다(그래서 이 docker 가이드에서는 Mac과 Ubuntu 호스트만 언급하는 것 같습니다). Linux 서브시스템(v1)에서 명령어를 실행해 보았지만, Docker를 Linux 서브시스템이 아니라 Windows에 설치했기 때문에 docker 단계에서 당연히 실패했습니다.


다음으로 Windows용 git bash에서 실행해 보았습니다. d/boot_dev --init는 실행할 수 없었습니다(에러: “d/boot_dev: Is a directory”), 하지만 bin/docker/boot_dev --init는 실행할 수 있었습니다. 이 명령어는 많은 pulls를 수행하면서 훨씬 더 진전을 보였지만, 결국 다음과 같은 오류로 실패했습니다.

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.

아래 링크에 설명된 대로 마운트 경로를 이스케이프 처리하여 이 문제를 해결할 수 있었습니다(생각하기로는요):
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개의 좋아요

저희 중 많은 분들이 슬로우 링(slow ring)을 사용하면서 전혀 문제가 없습니다. 게임도, 스팀도, 모든 것이 정상적으로 작동합니다.

두려움을 느끼시는 마음은 이해하지만, 실제로는 큰 문제가 아닙니다. 만약 이 방식이 너무 불안하시다면 Hyper-V나 VirtualBox 같은 전통적인 가상 머신을 추천합니다. 그 안에 Docker를 설치하고 저희의 Docker 개발 환경을 사용하시면 됩니다.

6개의 좋아요

이 컴퓨터가 내 주력(이자 유일한) 컴퓨터가 아니라면 슬링 라인을 따라가겠지만, 그렇게 위험을 감수할 수는 없습니다. 그래서 도커를 사용하는 전통적인 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 명령을 실행하면 "Run bundle install to install missing gems."라는 메시지가 표시됩니다. 그런데 이번에는 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를 실행할 수 없는 상태입니다. 이것이 pull(코드 가져오기)과 직접적이든 간접적이든 관련이 있는지, 아니면 완전히 무관한 문제인지 알 수 없습니다. 오류 메시지를 검색해 보았지만 큰 도움이 되지 않아, 어떻게 진행해야 할지 모르겠습니다.

1개의 좋아요

rubygems.org에 접속할 수 있었나요?

1개의 좋아요