Setting up Plausible Analytics using podman

Setting up Plausible Analytics using podman
Photo by Choong Deng Xiang / Unsplash

This is a continuation of my previous blog on using Ghost blog and podman.
As part of my use case, I wanted to be able to track readership of my articles to make sure they continue to be relevant and useful. I chose Plausible Analytics to keep things simple. One reason is that I can also selft host Plausible in a container and on a pod on its own on the same server.

Please refer to their website if you would like to explore more, https://plausible.io/

First steps,

A quick note before we begin, I decided to use the Plausible Analytics Community Edition to help me build my knowledge about this product.

Within the same Linux server and the podmantest sites subdirectory, I created a folder called analytics. It has subdirectories with the following structure as shown in the screenshot.

Here is the content of the docker-compose.yml file.

version: "3.3"
services:
  plausible_db:
    image: postgres:16-alpine
    restart: always
    volumes:
      - ~/sites/analytics/apps/plausible/db-data:/var/lib/postgresql/data:Z
    environment:
      - POSTGRES_PASSWORD=postgres
        
  plausible_events_db:
    image: clickhouse/clickhouse-server:24.3.3.102-alpine
    restart: always
    volumes:
      - ~/sites/analytics/apps/clickhouse/event-data:/var/lib/clickhouse:Z
      - ~/sites/analytics/apps/clickhouse/event-logs:/var/log/clickhouse-server:Z
      - ~/sites/analytics/clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
      - ~/sites/analytics/clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
    ulimits:
      nofile:
        soft: 262144
        hard: 262144
  
  plausible:
    image: ghcr.io/plausible/community-edition:v2.1.1
    restart: always
    command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
    depends_on:
      - plausible_db
      - plausible_events_db
    env_file:
      - plausible-conf.env
    ports:
      - 0.0.0.0:8003:8000

Here is the content of the plausible-conf.env file.

BASE_URL=http://analytics.test.com.au
SECRET_KEY_BASE=H3vxTtuUvNy3QpuVdfhoDtuR0QuZCdd/nVUDiYjVJpTxF7IFIaFiqXkH0M5qWNtY
TOTP_VAULT_KEY=nQ6FAnfPXu2Bx+ublcFo2WK5gCUB7CEiNKa+IrBrlFw=

Please lookup this link to find out what these values mean and how to generate them, https://github.com/plausible/community-edition/

Building the pod,

Once everything is in place, run the following command.

podman-compose --in-pod true up

Tip #1 - podman-compose will group the containers in a pod by default. For some reason I kept getting errors starting all the containers in the pod. One work around I discovered through trial and error, was to create an empty pod before running the podman-compose command.

podman pod create pod_analytics

Here is the command line output that shows the podman-compose command built the containers successfully.

The Plausible Analytics pod should now be up and running.

Here is the screenshot from the cockpit interface.

Here is the web url associated with the nominated 8003 port.

Tip #2 - After creating your administrator account, make sure to enable two factor authentication on the account for additional security.

The final step is to expose these sites using the Caddy reverse-proxy application.

Enjoy!

Read more