使用 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
    # 等待:
    #   - 依赖项已安装,
    #   - 数据库已迁移,以及
    #   - 创建了一个管理员用户(您需要与之交互)

# 在一个终端中:
d/rails s

# 并在一个单独的终端中
d/ember-cli

…然后在 http://localhost:4200 上打开浏览器,瞧!您应该会看到 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
Installing Discourse for macOS Development Using asdf and docker-compose
How to install Discourse locally?
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
Discourse on local pc
Discourse developement environment setup
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
Which is the better option to self-host?
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'
Adding command line tools support for user api keys
Install plugins in your non-Docker development environment
Adding command line tools support for user api keys
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
Can't set up dev environment due to cppjieba_rb failing to install
Allow subscription of predetermined length
Cannot load any images “Uncaught (in promise) no-response: no-response”
Discovery document is missing
Discourse API developers docker-compose basic image
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
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?
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
Availability of OpenID Connect in hosted plans
Tags rearranged, triggering an extra edit
Migrate a phpBB3 forum to Discourse
OAuth2 and Microsoft ADFS
Install Discourse for Development using Docker is Failed
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
Install on macOS – Failure: Scheduler::Defer can pause and resume
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)
Install on macOS – Failure: Scheduler::Defer can pause and resume
How can I install Discourse on Windows? Getting restarting (100) error
Stuck in infinite loop in Mac terminal after source ~/.bashrc
I want to install a plugin for development, what should I do?
Can't set up dev environment due to cppjieba_rb failing to install
Total newbie struggling to preview the signup modal with my test theme, what am I missing?
Configure Discourse to use a separate PostgreSQL server
`script/osx_dev` script is pretty broken
Issue in setup discourse on ubuntu server
Bundle install fails after adding gem "mysql2" and gem "reverse_markdown"
Using a launcher built docker image in docker-compose
Developing Discourse using a Dev Container
Can't uninstall on Ubuntu 18.04
I want to install a plugin for development, what should I do?
Without any coding knowledge, is it possible to install and maintain Discourse?
Using a launcher built docker image in docker-compose
Discourse redirects to the OAuth server after loading `/?authComplete=true`
Hello from Gitpod! (installing on google cloud + automated dev setup)