# Developing Discourse using a Dev Container

**URL:** https://meta.discourse.org/t/developing-discourse-using-a-dev-container/336366
**Category:** Developer Guides
**Created:** [November 15, 2024, 4:44pm UTC](https://meta.discourse.org/t/developing-discourse-using-a-dev-container/336366 "2024-11-15T16:44:08Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [November 15, 2024, 4:44pm UTC](https://meta.discourse.org/t/developing-discourse-using-a-dev-container/336366/1 "2024-11-15T16:44:08Z")

</div>

[Dev Containers](https://containers.dev/) 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

1. [Download and install](https://code.visualstudio.com/) VSCode

2. Install the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) in VSCode

3. Clone the Discourse repository onto your machine

4. In VSCode, use `File` → `Open Folder`, then choose the Discourse directory

5. 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…”

6. 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…”

7. 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.

8. Run the default build task using Cmd/Ctrl + Shift + B.

9. Run the `dev/admin/create` task. Open the command palette and search for “Tasks: Run Tasks”. It will present a menu of tasks; select `dev/admin/create` off of that list. You’ll be prompted to enter an email address and a password for your admin user.

10. Visit `http://localhost:3000` in your browser to see your new Discourse instance

11. All done! You can now make changes to Discourse’s source code and see them reflected in the preview.

## Running tests

The first time you run tests, you’ll need to install testing dependencies, including Playwright and the `discourse_test` DB. You can run the `deps/testing` task to install those. Open the command palette, select “Tasks: Run Tasks”. It will present a menu of tasks; select `deps/testing` off of that list.

Once the test dependencies are installed, you can run [`bin/lint`](https://meta.discourse.org/t/132947), [`bin/qunit`](https://meta.discourse.org/t/66857), or the [system specs](https://meta.discourse.org/t/325937)

## 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

- [Development container specification](https://containers.dev/)

- [VSCode devcontainer docs](https://code.visualstudio.com/docs/devcontainers/containers)

* * *

This document is version controlled - suggest changes [on github](https://github.com/discourse/discourse/blob/main/docs/developer-guides/docs/02-development-environments/01-devcontainer.md).

---

_[View the full topic](https://meta.discourse.org/t/developing-discourse-using-a-dev-container/336366)._
