Hosting using Dokku

I could not find a complete guide on how to do this. But putting together pieces from other sources helped me get up and running faster. Sources are listed at the bottom of the page.

Let's get started!

On your local pc
Create a git repo with a dockerfile that we can push to a dokku remote:

mkdir rocket-chat

cd rocket-chat

git init .

touch Dockerfile

echo "FROM" >> Dockerfile

git add .

git commit -m "Created dockerfile for"

git remote add dokku dokku@your-server-ip:app-name # Important to use the same app-name as in dokku in later steps.

On your dokku server
Install mongodb for dokku, if you don't alerady have it

sudo dokku plugin:install mongo

Create the dokku application (name of app should be the same as you specified as your git remote in the beginning)

dokku apps:create <name of app>

Set up the database. This is where we deviate from the standard setup, because chat rocket needs a replica.

# create db
dokku mongo:create <your db name> --config-options "--replSet rs0 --keyFile /data/db/replica.key --storageEngine wiredTiger --auth"
# it will fail to start initially

# go to db folder
cd /var/lib/dokku/services/mongo/<your db name>/data

# generate keyfile and set permissions
openssl rand -base64 756 > replica.key
chown dokku replica.key
chmod 400 replica.key

# restart db
dokku mongo:stop <your db name>
dokku mongo:start <your db name>

# connect to db and setup replica config
dokku mongo:connect-admin <your db name>
> use admin
> rs.initiate() # create the replicaset configuration
rs0:SECONDARY> use local
rs0:PRIMARY> db.createUser({
  user: "oploguser", 
  pwd: "<your own secret password>", 
  roles: [{role: "read", db: "local"}]})
rs0:PRIMARY> exit

Now the db should be up and running, and we should link it to the dokku application, and set ENV-variables correctly

# link db
dokku mongo:link <your db name> <name of app>

#check your applications ENV vars
dokku config <name of app>

# Notice the MONGO_URL env. The structure is the following:
# mongodb://username:password@hostname:port/db-name
# now replace the username with oploguser and password with the password you set in the previous step, and use the same hostname and port as in MONGO_URL.
dokku config:set <name of app> MONGO_OPLOG_URL=mongodb://oploguser:<your secret password (from step above)>@dokku-mongo-<your db name>:27017/local?authSource=admin&replicaSet=rs0

Now go back to your local pc and push to dokku

git push dokku master

Add domain and proxy

# add domain
dokku domains:set <name of app> <domain>

# add proxy
dokku proxy:ports-add <name of app> http:80:3000

# enable ssl
dokku letsencrypt:enable <name of app>