# Install Discourse for development using Docker

**URL:** https://meta.discourse.org/t/install-discourse-for-development-using-docker/102009
**Category:** Developer Guides
**Tags:** docker, dev-install, how-to
**Created:** [November 16, 2018, 9:40am UTC](https://meta.discourse.org/t/install-discourse-for-development-using-docker/102009 "2018-11-16T09:40:04Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [November 16, 2018, 9:40am UTC](https://meta.discourse.org/t/install-discourse-for-development-using-docker/102009/1 "2018-11-16T09:40:04Z")

</div>

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

✅ Pros: No need to install any system dependencies, no configuration needed at all for setting up a development environment quickly.

❌ 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](https://meta.discourse.org/t/developing-discourse-using-a-dev-container/336366)

## Step 1: Install Docker

### Ubuntu

```sh
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

```sh
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

> ⚠ 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](https://github.com/discourse/discourse/pull/13117) in QEMU.
> 
> Instead, you should use [Install Discourse on macOS for development](https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-macos-for-development/15772)

_Option 1:_ Download a packaged `.dmg` from the [Docker store](https://store.docker.com/editions/community/docker-ce-desktop-mac)  
_Option 2:_ `brew install docker`

## Step 2: Start Container

Clone Discourse repository to your local device.

```sh
git clone https://github.com/discourse/discourse.git
cd discourse

```

_(from your source root)_

```sh
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/dev --only ember

```

…then open a browser on [http://localhost:3000](http://localhost:3000) 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:

```sh
d/shutdown_dev; d/boot_dev

```

* * *

**Notes:**

- To test emails, run MailHog :

- If there are missing gems, run:

- If a db migration is needed:

- When you’re done, you can choose to kill the Docker container with:

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

- If you see errors like “_permission denied while trying to connect to Docker_”, Run:

- If you wish to globally expose the ports from the container to the network (default off) use:

- The Dockerfile comes from [discourse/discourse\_docker on GitHub](https://github.com/discourse/discourse_docker), in particular [image/discourse\_dev](https://github.com/discourse/discourse_docker/tree/main/image/discourse_dev).

## Running Tests

```sh
d/rake autospec

```

To run specific plugin tests, you can also do something like this:

```sh
d/rake plugin:spec["discourse-follow"]

```

Or even something like this to be even more specific:

```sh
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](https://github.com/discourse/discourse/blob/main/docs/developer-guides/docs/02-development-environments/03-docker-setup.md).

---

_[View the full topic](https://meta.discourse.org/t/install-discourse-for-development-using-docker/102009)._
