How To Easily Set Up Plausible With Docker (Step-by-Step)

2 Comments
Published: 14.08.2022

Do you want to set up Plausible Analytics for your Website or Web Application with Docker? In this step-by-step guide, we will first look at what Plausible is and then how to set it up!

What is Plausible?

Plausible is a simple and lightweight, open-source analytics software as an alternative to Google Analytics. One reason why you should consider it over Google Analytics is that it does not use cookies and thus is GDPR, CCPA, and PECR compliant (for their hosted version) as stated on their website here.

Server icon

VPS Hosting Course

Learn everything you need to know about servers and hosting your own applications!

The hosted version of Plausible Analytics stores all the data in EU data centers and thus complies with the named regulations.

In the following setup on the other hand I will show you how to self-host and set up plausible analytics with docker!

Docker setup for Plausible

Setting up Plausible Analytics with Docker is pretty simple. You need to create the following four containers:

Plausible itself offers a pretty good docker-compose template (here), that I modified a little bit for my needs:

Need help or want to share feedback? Join my discord community!

services:    
    plausible_mail:
        container_name: plausible_mail
        image: bytemark/smtp
        restart: unless-stopped

    plausible_db:
        container_name: plausible_db
        image: postgres:12
        restart: always
        volumes:
            - ./plausible/data:/var/lib/postgresql/data
        environment:
            - POSTGRES_PASSWORD=<postgres-pwd>

    plausible_events_db:
        container_name: plausible_events_db
        image: yandex/clickhouse-server:21.3.2.5
        restart: unless-stopped
        volumes:
            - ./plausible/event-data:/var/lib/clickhouse
            - ./plausible/clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
            - ./plausible/clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
        ulimits:
            nofile:
                soft: 262144
                hard: 262144

    plausible:
        container_name: plausible
        image: plausible/analytics:latest
        restart: unless-stopped
        command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh db init-admin && /entrypoint.sh run"
        depends_on:
            - plausible_db
            - plausible_events_db
            - plausible_mail
        ports:
            - "8000:8000"
        # use expose if you use my nginx setup (link in conclusion)
        # expose:
        #     - "8000"
        environment: 
            ADMIN_USER_EMAIL: <admin-mail>
            ADMIN_USER_NAME: <admin-user>
            ADMIN_USER_PWD: <admin-pwd>
            BASE_URL: <base-url-of-the-domain-your-plausible-is-hosted-on>
            SECRET_KEY_BASE: <generate-me>

After building all containers by running docker-compose up -d or docker compose up -d you can access plausible under your machine’s IP with the port 8000. For example http://localhost:8000.

To generate to content of SECRET_KEY_BASE run openssl rand -base64 64 | tr -d '\n' ; echo , after it is generated copy the output into the field.

KOFI Logo

If this guide is helpful to you and you like what I do, please support me with a coffee!

Set up a Website for Tracking in Plausible

In this section, we will add a new Website for tracking to our newly created Plausible instance. For that we first need to log in with the data set in the plausible container and then follow these steps:

  1. Click on “+ Add a website”
  2. Add your domain and select a timezone
  3. Copy the snippet and add it to the HTML head of your website!

In case you get an error when waiting for the snippet you can also access it in your websites settings by hovering over the site and clicking on the settings gear:

Setup Plausible With Docker: Website settings gear

Then you find the snippet under General > JavaScript snippet. Here you can also click on the “i” to get a better explanation of how to add it to your site.

Conclusion

Setting up Plausible Analytics with Docker for your website is super simple and has a lot of benefits. I’m using Plausible for some months now and can only recommend it. In case you want to set it up with HTTPS check out my guide on an automated SSL and Reverse-Proxy setup here.

How do you like Plausible?

I hope this guide helped you in setting up Plausible on your own and if you liked my content consider subscribing to my monthly newsletter.

Discussion (2)

Add Comment

Your email address will not be published. Required fields are marked *