This is an advanced setup. Don’t follow this unless you are experienced with Linux server administration and Docker.
2 Container Setup for a New Site
Added by @pfaffman 2019-12-11.
NOTE: If you want to create a 2 container site you can do this:
./discourse-setup --two-container
It works just like normal except it’ll create separate data
and web_only
containers and generate a random password for the database. If you already have an app.yml
you’ll need to rename it, or discourse-setup
will just update it. You could then copy a backup into /var/discourse/shared/web_only/backups/default
and restore that, which is a little easier for novice system administrators than what’s described below.
Converting your Current Setup
I managed to migrate to two containers. If anyone else needs instructions, this is how it worked for me.
The process includes backup, setting up separate web and data containers and restore data.
-
Backup your discourse instance and download backup. You can follow the simple guide or backup and restore later manually.
-
Stop current standalone container
./launcher stop app
-
copy
web_only.yml
anddata.yml
fromsamples/
tocontainers/
rename them to whatever you’d like, e.g.web_rocks.yml
anddata2.yml
. -
if you rename them, please pay attention to the entries
volumes:
indata.yml
andweb_only.yml
If you renamedweb_only.yml
toweb_rocks.yml
you need to modify the entry inWeb_rocks.yml
like this:
volumes:
- volume:
host: /var/discourse/shared/web_rocks
guest: /shared
- volume:
host: /var/discourse/shared/web_rocks/log/var-log
guest: /var/log
Accordingly, do the similar editing in data.yml
also.
Setting up data container
Start with data.yml
and set a password for the database. Then:
- come to the container’s root folder
/var/discourse
- run
./launcher bootstrap data2
(data2 or whatever new name you gave it) - run
./launcher start data2
(using new name again) - if everything goes smoothly you can connect to the container via:
./launcher enter data2
(again using the new name) - Exit the container by
exit
.
Setting up web container
Let’s modify web_only.yml
.
Firstly, change the template and expose ports as your app.yml
does.
Secondly, make sure you are linking to the right data container. If you renamed the data.yml to ‘something_else’ put it in for ‘name’.
# Use 'links' key to link containers together, aka use Docker --link flag.
links:
- link:
name: data
alias: data
Although we don’t want to expose ssh or any other ports anymore, you’d still need to expose 80 and 443 port for web access. This depends on whether you have a nginx running in the front and how you connect container with it.
Somewhere in there you’ll find this block:
DISCOURSE_DB_USERNAME: discourse
DISCOURSE_DB_PASSWORD: mypassword
DISCOURSE_DB_HOST: data
DISCOURSE_REDIS_HOST: data
- Enter the password you set inside the data container.
- Enter the data container’s alias you just wrote down. For
DB_HOST
and forREDIS_HOST
. It has to match the links block we mentioned. - You probably didn’t change the
DB_USERNAME
.
You’ll find the values for DISCOURSE_DEVELOPER_EMAILS
and DISCOURSE_HOSTNAME
and many more. You already have these values in your app.yml
. Copy them from there.
In the hooks section remember to set any additional plugins you already use inside app.yml
Now you should be ready to bootstrap it:
./launcher bootstrap web_only
(again with your new/own name)
Once bootstrapped, you can start web_only
(use your new name):
./launcher start web_only
When Discourse is ready, login and restore your site.
After this, everything worked again for me and my discourse installation was running again, but now in two separate containers.
How to update when using separate web and data containers
If you do not care about the few minutes of downtime:
./launcher stop web_only && ./launcher rebuild data && ./launcher rebuild web_only
If you care about every minute of downtime:
for data
:
./launcher bootstrap data && ./launcher destroy data && ./launcher start data
for web_only
:
./launcher bootstrap web_only && ./launcher destroy web_only && ./launcher start web_only
It’s enough to rebuild web_only
and skip data
except when there is an upgrade to postgres or redis. Those happen on the order of once a year and you’ll see an announcement like PostgreSQL 13 update when it happens.
Managing a two-container installation
@pfaffman will one day create a topic about this, but until then, there is this: Managing a Two-Container Installation - Documentation - Literate Computing Support