Dev Containers is an open standard for configuring a development environment inside a container. This almost entirely eliminates the need to install/configure Discourse-specific tools/dependencies on your local machine, and makes it very easy to keep up-to-date as Discourse evolves over time.
Dev Containers can be used in a number of different IDEs, or directly using their reference CLI. This guide will describe the setup process for VSCode.
In VSCode, use File â Open Folder, then choose the Discourse directory
Open the folder in its Dev Container. This can be done via the popup prompt, or by opening the command palette (Cmd/Ctrl + Shift + P) and searching for âOpen folder in containerâŚâ
If this is your first time launching a container, you will be prompted to install and start Docker Desktop. Once complete, go back to VSCode re-run âOpen folder in containerâŚâ
Wait for the container to download and start. When itâs done, the README will appear, and youâll see the Discourse filesystem in the sidebar.
Run the default build task using Ctrl + Shift + B (Cmd + Shift + B on mac).
This will install dependencies, migrate the database, and start the server. Itâll take a few minutes, especially on the lower-end machines. Youâll see âBuild successfulâ in the terminal when itâs done.
Visit http://localhost:4200 in your browser to see your new Discourse instance
All done! You can now make changes to Discourseâs source code and see them reflected in the preview.
Applying config/container updates
Every so often, the devcontainer config and the associated container image will be updated. VSCode should prompt you to ârebuildâ to apply the changes. Alternatively, you can run âDev Containers: Rebuild Containerâ from the VSCode command palette. The working directory, and your Redis/Postgres data will be preserved across rebuilds.
If youâd like to start from scratch with fresh database, youâll need to delete the discourse-pg and discourse-redis docker volumes. This can be done from the âRemote Explorerâ tab of the VSCode sidebar.
Discourseâs sample vscode .vscode/settings.json and .vscode/tasks.json will be copied when you first boot the codespace. From that point forward, if you want to use the latest sample config, youâll need to manually copy .vscode/settings.json.sample to .vscode/settings.json.
When using the docker container from outside via the scripts in d/ (e.g. d/boot_dev --init as specified in Install Discourse for development using Docker , it asks me to set up an admin account as part of the process.
However, when using it as a Dev Container and running the build steps (ctrl/cmd + shift + b) it does NOT create an admin.
From glancing at the instructions, I first had the impression that creating an admin is quite arduous; but then I realized that all it takes is this command, leaving it here for those who run into the same issue:
rake admin:create
(or, if it complains about a different rake version required: bundle exec rake admin:create)
On Windows 11, if you donât want to run into line ending issues, such as:
[23963 ms] Start: Run in container: /bin/sh -c ./.devcontainer/scripts/start.rb
/usr/bin/env: âruby\râ: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines
Maybe there is a better way, but to work on plugins I have a discourse-plugins sibling folder alongside my main discourse repo folder. This mounts to /workspace/plugins so I can then create symlinks within the container.
This is what I added to mounts in devcontainer.json: "source=${localWorkspaceFolder}/../${localWorkspaceFolderBasename}-plugins,target=/workspace/plugins,type=bind"
If you are using OrbStack (not affiliated) on your local macOS environment, and want to run Discourse on HTTPS with a custom domain, update your devcontainer.json with following additions:
Give a name to the container.
Add the matching hostname to RAILS_DEVELOPMENT_HOSTS environment variable.
p.s. please let me know, if you know how I can set the *.orb.local hostname and the container name dynamically, as it is defined for GitHub Codespaces. Setting the value as .app.github.dev,.orb.local didnât work for me.