Comentario: your Blog or Website's Comment Companion

Selfhosted commenting using docker
Photo by Kelly Sikkema / Unsplash

Online communities are a big part of the internet, and a big part of community is the ability to comment and engage with content creators.

Today we're going to install Comentario, a standalone commenting tool which can be embedded into any website. Scroll down to the bottom of this (or any other) article on my site and you'll see it in action.

šŸ’”
A few years back I wrote about Commento (note the name difference) which has since been abandoned (you can find the post here). Comentario is a fork and is still actively maintained.

As always we start with

Prerequisites

You'll need the following:

  1. Docker and docker-compose installed on your machine
  2. The ability to SSH / use CLI/terminal on your machine, or use Portainer to spin up your docker stacks
  3. Some sort of access and relevant permissions to manage and create new directories
  4. A Fully Qualified Domain Name (FQDN, e.g. pointtosource.com)
  5. A reverse proxy or tunnel set up, on its own docker network (for instance called proxy) with the relevant SSL certificate(s) (check out my SWAG article for some info on how to do that if you haven't already)
  6. The name of the network you have your reverse proxy connected to
  7. A way to make sure that your machine's firewall will allow communication between containers on the same docker network
  8. An SMTP email address and credentials (if you want to be able to send emails to users or yourself)

Prepping the installation

Comentario needs a few things set up before spinning up the stack.

  1. Files and folders
  • Inside your docker directory create the following
    • A folder called db
    • A file called docker-compose.yml
    • A file called secrets.yaml

If you SSH into your machine, you can copy paste the following to create all three at the same time

mkdir db && touch docker-compose.yml secrets.yaml
  1. Populating the docker-compose.yml
  • Open the file, and paste the following into it:
networks:
  proxy: #change to the name of your reverse proxy network
    external: true
  default:
    name: comentario
    ipam:
      config:
        - subnet: 172.20.1.0/28 #change this network IP as necessary

services:
  comentario-db:
    image: postgres:16-alpine
    container_name: comentario-db
    environment:
      POSTGRES_DB: comentario-db
      POSTGRES_USER: comentario-user
      POSTGRES_PASSWORD: comentario-pwd
    volumes:
      - ./comentario/db:/var/lib/postgresql/data    
    ports:
      - "4523:5432"

  comentario:
    image: registry.gitlab.com/comentario/comentario:v3.0.0-rc1
    container_name: comentario
    environment:
      BASE_URL: https://comentario.yourdomain.com #change to your intended domain
      SECRETS_FILE: "/secrets.yaml"
      #comment the following if you don't want to use email
      EMAIL_FROM: email@yourdomain.com #change to your email address
    ports:
      - "8080:80" #change before the `:` if necessary to avoid port clash
    volumes:
      - ./secrets.yaml:/secrets.yaml:ro
    networks:
      - proxy #change as above if you changed line 2
      - default
  1. Populating the secrets.yaml
  • Open the file and add the following:
postgres:
  host:     comentario-db
  port:     5432
  database: comentario-db
  username: comentario-user
  password: comentario-pwd

#comment out or delete the smtpServer block if you don't want to use email
smtpServer:
  host: #server IP or domain
  port: #smtp port
  username: #your account/email username
  password: #your account/email password
  encryption: #none, ssl, or tls
  • Make sure that under postgres your host matches the service name of the db container, and that your database, username and password all match what's in the docker-compose.yml

Spinning up the stack and accessing the GUI

You can now spin up your stack, and if you didn't change the port mapping you should be able to access the GUI at http://[NASIP]:8080.

  • Click 'Sign up here' and create your login credentials
  • Use those credentials to log in
šŸ’”
The first user to be created will be a superuser. Subsequent created users will be regular users

Configuring Comentario for your website

  • Click 'Domains' in the navigation pane on the left then click the green + New domain button
  • At the minimum add in the domain you want to add comments to (without the https://)
  • Add in a name, then click through the Moderation and Authentication tabs and select the options you want there
  • Click Create

The next screen shows you the code snippet you'll need to insert into your website or blog's code. If for instance you have a Ghost blog and want comments on every post you make, all you need to do is find your post.hbs and insert the code snippet in the part of the page you want it to appear.

There is access to a number of other configuration options. Some can be found in the GUI by clicking Configuration on the left and then the Dynamic tab. Others need to be included either in the docker-compose.yml or the secrets.yml and will only be read by the container at startup.

For a full list of those configuration options, click here.


Feel free to leave a comment below!