Docker setup for development


#1

Hello, I am working on setting up Discourse locally and am very confused. I have read that the “The only officially supported installs of Discourse are Docker based.” (discourse/INSTALL.md at master · discourse/discourse · GitHub) So I would like to set up with docker. However the guides only talk about setting up discourse directly on a DigitalOcean server. Thats great but doesn’t help me as I want to develop in discourse locally before ever deploying to a server. I am also confused because the main discourse GitHub only has links to a Vagrant install. So what is the official supported version, Vagrant or Docker? Can someone please point me in the direction to set up a discourse docker environment locally? Any help would be greatly appreciated. Thank you!


(Joshua Rosenfeld) #2

The only supported install version for production is Docker. For development (as you’ve noticed) you have far more options. Vagrant is one, if you want to do development locally in docker, see discourse/bin/docker at master · discourse/discourse · GitHub.


#3

Oh that makes sense. Thank you! I also dont have a ./discourse-setup script. So I am confused as to how to set up emails etc


(Joshua Rosenfeld) #4

The Discourse Setup script is intended for production. If you wish to use Docker for development, follow the guide I linked above.


#5

I am having some issues using docker in development and ran into this article saying that Docker is not for devlopment. These are a couple years old, has this changed? Development environment: Vagrant or Docker?


(Joshua Rosenfeld) #6

I do believe things have changed. But I’m not an engineer. @sam can confirm.


#7

By any chance is there a guide to using docker and discourse in development? I am new to docker, so maybe I am missing something, but it looks like I need to have ‘./bin/docker/’ before all my commands. Why doesn’t docker-run work?


(Joshua Rosenfeld) #8

The guide is linked to in my second post: discourse/bin/docker at master · discourse/discourse · GitHub.

You need to complete the following:

  1. Install git.
  2. Clone Discourse locally.
  3. Install docker.
  4. Run the two commands in the guide.

#9

Thanks for answering so fast Joshua. Let me clarify. I have followed the commands in that link and am running the discourse server locally through docker. Now I want to run commands such as ‘rake db:migrate’ but how do I run those commands within the docker container? I am also confused as I dont see a Dockerfile or docker compose. My understanding is that when using docker I should be able to run ‘docker-run rake db:migrate’ to migrate the db within the docker container.


(Gerhard Schlager) #11

Take a look at all the scripts inside bin/docker. They are very helpful and one of them is migrate.

So, calling ./bin/docker/migrate will migrate your development and test database.
Of course you can also use ./bin/docker rake if you want to execute other rake tasks.

You can also follow the instructions of the Beginners Guide to Install Discourse on Ubuntu for Development if you don’t want to use the Docker based environment.


#12

If you take a look at the scripts in discourse/bin/docker at master · discourse/discourse · GitHub

boot_dev creates and runs a container in detached mode, and rails/rake/etc utilizes docker exec to run the respective commands in the existing container, which are intended to make running those commands easier.

As for the Dockerfile question, it is answered in the README linked before: discourse/README.md at master · discourse/discourse · GitHub


There is a folder d at the project root symlinked to bin/docker, thus you can actually do d/boot_dev, d/rails s, etc.


#13

Thanks everyone! Its all starting to come together. @xrav3nz I am not having any success with docker exec as it says ‘Error: No such container <rails, rake, etc>’. However the ‘d/’ works as I expected. Is there any reason to use docker exec over d/ ?


#14

Have you ran d/boot_dev --init first? If so, then d/rails, d/rake, etc should work fine.

Of course you can manage/interact with the container directly yourself, but I’d say the helper scripts are … helpful? I hack on Discourse locally with the Docker setup, and the helper scripts are all I need so far.


EDIT: just realized your question was regarding using docker exec specifically, in that case, I recommand checking out the official reference (or the helper scripts themselves) and then you will see the necessary syntax to interact with an existing container.


#15

After reading the docs I realized I wasn’t specifying a container. So if you were to use docker exec to migrate your database, would you just run ‘docker exec rake db:migrate’ or ‘docker exec discourse_dev rake db:migrate’? The second option appears correct from the docker docs, but it says that there was no Rakefile found. Running ‘docker ps’ shows that discourse_dev is the only container I have running. So now I am wondering if ‘d/rake db:migrate’ is running in the discourse_dev container or something else?


(Michael Brown) #16

The scripts under d are helpers that automatically execute commands inside the container - I would suggest looking at them if you’re curious:

± |master ✓| → cat d/rake
#!/bin/bash

PARAMS="$@"
CMD="cd /src && RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 LD_PRELOAD=/usr/lib/libjemalloc.so RAILS_ENV=${RAILS_ENV:=development} bundle exec rake $PARAMS"
docker exec -it -u discourse:discourse discourse_dev /bin/bash -c "$CMD"

(Chris Beach) #17

I think it would be wise to remove the Vagrant option and focus on Docker development, updating and clearing out any redundant documentation.

Fledgling developers would benefit from a development portal (a wiki topic linked from the top nav) that, in turn, linked to the current state of the art guidance, and to plugins that are well maintained and serve as canonical examples for developers.


(Erlend Sogge Heggen) #18

Also see this: