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

…then open a browser on http://localhost:4200 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.

72 إعجابًا
Install Discourse on Ubuntu or Debian for Development
Using a launcher built docker image in docker-compose
IDE and comfortable DEV environment for newbies
Configure Discourse to use a separate PostgreSQL server
Docker install on MacOS
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
Discourse developement environment setup
Installing Discourse for macOS Development Using asdf and docker-compose
Discourse on local pc
How to install Discourse locally?
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?
Install Discourse on Ubuntu or Debian for Development
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)
Clean-up html tags in all posts after migration?
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”
External database ENV VARs not documented (external PG Port, external Redis ENV VARs)
What are the benefits of a dev environment?
Installing Discourse on windows using Docker Desktop
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
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
Total newbie struggling to preview the signup modal with my test theme, what am I missing?
Discovery document is missing
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
Using a launcher built docker image in docker-compose
Installing Discourse for macOS Development Using asdf and docker-compose
Installing Discourse for macOS Development Using asdf and 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
Dev Category sidebar
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)
How to Install Discourse on LocalHost in Windows?