Questions:
- Can we avoid installing Discourse as root? Cf. https://meta.discourse.org/t/install-issues-when-not-root/16538/17
Discourse is very clear that they do not support anything else than their official install instructions, which more or less requires a dedicated server.
However, being a docker image, it should be possible to install it on dokku.
These instructions are based on https://medium.com/batary/deploying-discourse-with-dokku-5eec28e2ad8b, and updated to work with current Discourse + Dokku.
Discourse has a repository dedicated to bootstrapping a docker image. We'll follow some of their instructions, but will adapt them to our needs.
On the server, clone the Official Discourse Docker Image:
git clone https://github.com/discourse/discourse_docker.git /var/discourse
cd /var/discourse
Instead of using the setup tool, we'll do the configuration manually. Copy the default standalone configuration and edit it:
cp samples/standalone.yml containers/app.yml
nano containers/app.yml
You'll need to at least set the following (SMTP is mandatory for Discourse to work):
## Required. Discourse will not work with a bare IP number.
DISCOURSE_HOSTNAME: 'discourse.example.com'
## Uncomment if you want the container to be started with the same
## hostname (-h option) as specified above (default "$hostname-$config")
#DOCKER_USE_HOSTNAME: true
## TODO: List of comma delimited emails that will be made admin and developer
## on initial signup example '[email protected],[email protected]'
DISCOURSE_DEVELOPER_EMAILS: '[email protected],[email protected]'
## TODO: The SMTP mail server used to validate new accounts and send notifications
# SMTP ADDRESS, username, and password are required
# WARNING the char '#' in SMTP password can cause problems!
DISCOURSE_SMTP_ADDRESS: smtp.example.com
#DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: [email protected]
DISCOURSE_SMTP_PASSWORD: pa$$word
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)
Do not set the Let's Encrypt email, as we'll manage SSL through dokku.
Save the config file and bootstrap the image:
./launcher bootstrap app
If successful, you should see an image named local_discourse/app
when you run the following command:
docker images
Now you can setup and configure the app with Dokku.
dokku apps:create discourse
dokku domains:set discourse discourse.example.com
dokku proxy:ports-add discourse http:80:80
dokku proxy:ports-remove discourse http:80:5000
The Discourse launcher actually runs a custom docker run
command, with a whole lot of arguments. We'll replicate it using dokku features.
Get the command used to start the Discourse instance:
./launcher start-cmd app
Replace the values with your output of the prior command, splitting by type of arguments:
-
Discard the
-p port:port
arguments -
Join all the
-e
ENV vars and set them like this:dokku config:set --no-restart discourse LANG=en_US.UTF-8 RAILS_ENV=production UNICORN_WORKERS=3 UNICORN_SIDEKIQS=1 RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 RUBY_GC_HEAP_INIT_SLOTS=400000 RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5 DISCOURSE_DB_SOCKET=/var/run/postgresql DISCOURSE_DB_HOST= DISCOURSE_DB_PORT= DISCOURSE_HOSTNAME=discourse.example.com [email protected] DISCOURSE_SMTP_ADDRESS=smtp.example.com [email protected] DISCOURSE_SMTP_PASSWORD=pa$$word DOCKER_HOST_IP=172.17.0.1
-
Set both
-v
volumes:dokku storage:mount discourse /var/discourse/shared/standalone:/shared dokku storage:mount discourse /var/discourse/shared/standalone/log/var-log:/var/log
-
Set the following Docker options (
--entrypoint
is especially important):dokku docker-options:add discourse run,deploy "--entrypoint /sbin/boot" dokku docker-options:add discourse run,deploy "--hostname dokku-discourse" dokku docker-options:add discourse run,deploy "--shm-size=512m" dokku docker-options:add discourse run,deploy "--mac-address aa:bb:cc:dd:ee:ff"
-
Set the restart policy
--restart
(this is probably optional):dokku ps:set-restart-policy discourse always
-
You should ignore other options like
-t
To make it easier, we'll deploy using the local docker image:
dokku git:from-image discourse local_discourse/app:latest
The app should deploy and then start.
dokku config:set --no-restart discourse [email protected]
dokku letsencrypt discourse
First thing: skip wizard and enable force_https
from admin dashboard (make sure to have setup letsencrypt and that https works fine). Then restart the wizard if you want.
Then follow the next steps to register an admin account.
You can also add plugins and more.
Based on default update instructions, with a twist because of dokku:
dokku ps:stop discourse
cd /var/discourse/
./launcher bootstrap app
# wait for it...
dokku git:from-image discourse local_discourse/app:latest
Make sure to backup contents in /shared
, cf.
## The Docker container is stateless; all data is stored in /shared
volumes:
- volume:
host: /var/discourse/shared/standalone
guest: /shared
I've created a plugin to make this easier: https://github.com/badsyntax/dokku-discourse