[Docker] Matomo on Synology NAS

[Docker] Matomo on Synology NAS

Back in the day, I used to rely on Piwik, an open-source web analytics tool, for tracking visitors on my blog.
Then one day, Piwik suddenly announced it was rebranding as Matomo, which left me a little confused. Around that same time, life got busier, I leaned more on Google Analytics (which was “good enough”), and eventually stopped blogging altogether.

Now that I’m reviving my blog, I remembered the convenience of Piwik and decided to give its successor, Matomo, another try — this time running it inside Docker on my Synology NAS.


Folder Structure (Example)

/volume1/docker/matomo/
├── docker-compose.yml # Project root (run docker compose up here)
├── db/ # MariaDB database files
└── data/ # Matomo config (config.ini.php, etc.)

Installation with Docker

Fortunately, installing Matomo with Docker is no harder than spinning up any other container. Here’s the docker-compose.yml I used:

networks:
  matomo-net:
    driver: bridge

services:
  # ── MariaDB database for Matomo ──────────────────────────────
  db:
    image: mariadb:11.4
    container_name: matomo-db
    hostname: matomo-db
    restart: unless-stopped
    command:
      - --max_allowed_packet=1073741824       # Allow very large packets
      - --character-set-server=utf8mb4        # Full UTF-8 charset
      - --collation-server=utf8mb4_unicode_ci # Recommended collation
    environment:
      MARIADB_ROOT_PASSWORD: your-own-password
      MARIADB_DATABASE: matomo
      MARIADB_USER: matomo
      MARIADB_PASSWORD: your-own-password
      TZ: Asia/Seoul
    volumes:
      - /volume1/docker/matomo/db:/var/lib/mysql:rw
    networks: [matomo-net]

  # ── Main Matomo application (Web UI) ─────────────────────────
  matomo:
    image: matomo:latest
    container_name: matomo
    depends_on:
      - db
    environment:
      TZ: Asia/Seoul
      MATOMO_DATABASE_HOST: matomo-db
      MATOMO_DATABASE_USERNAME: matomo
      MATOMO_DATABASE_PASSWORD: your-own-password
      MATOMO_DATABASE_DBNAME: matomo
      # ⚠️ If using a reverse proxy, set 'trusted_proxies' in config.ini.php
    ports:
      - "8096:80"  # Expose Matomo on host port 8096
    volumes:
      - /volume1/docker/matomo/data:/var/www/html/config:rw
    restart: unless-stopped
    networks: [matomo-net]

  # ── Background worker: runs Matomo archiving every hour ──────
  matomo-cron:
    image: matomo:latest
    container_name: matomo-cron
    depends_on:
      - db
      - matomo
    environment:
      TZ: Asia/Seoul
      MATOMO_DATABASE_HOST: matomo-db
      MATOMO_DATABASE_USERNAME: matomo
      MATOMO_DATABASE_PASSWORD: your-own-password
      MATOMO_DATABASE_DBNAME: matomo
    volumes:
      - /volume1/docker/matomo/data:/var/www/html/config:rw
    entrypoint: ["/bin/sh", "-c", "trap 'exit 0' TERM INT; while :; do php /var/www/html/console core:archive --url=http://matomo/ > /proc/1/fd/1 2>/proc/1/fd/2; sleep 3600; done"]
    restart: unless-stopped
    networks: [matomo-net]

A couple of notes:

  • The cron container is optional but strongly recommended, because it pre-generates reports so that the Matomo dashboards load quickly.
  • If you’re running behind Synology’s reverse proxy, don’t forget to adjust your config.ini.php and add your proxy IPs under trusted_proxies.

Installing Matomo is the easy part. The harder (and more important) part comes afterward: compliance.

Different countries have strict privacy laws regarding tracking analytics. Things like IP addresses are considered personal data in the EU and elsewhere. If you’re collecting visitor data, you need to understand the regulations that apply to your audience’s country.

To be honest, this is still confusing to me, and I’m still learning. But thankfully, there are tools and plugins that can help. For example:

Even with such plugins, I often find the legal details overwhelming. But at the very least, they help you put up banners, disclaimers, and consent dialogs that are now mandatory in most regions.


Closing Thoughts

Revisiting Matomo felt like reconnecting with an old friend. It’s still just as powerful, still focused on user privacy, and now better integrated with Docker workflows.

For personal blogs, side projects, or even small businesses that want Google-Analytics-like insights without giving all their data to Google, Matomo is a fantastic option.

Just remember: installation may be simple, but privacy compliance is not optional.
If you want to track your visitors responsibly, make sure to also invest time in understanding (and implementing) the laws relevant to your region.