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.
Getting started
-
Download and install VSCode
-
Install the Dev Containers extension in VSCode
-
Clone the Discourse repository onto your machine
git clone https://github.com/discourse/discourse
-
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
.
References
This document is version controlled - suggest changes on github.