HUB
Sign inSign up

ideaplexus/matomo

By ideaplexus

•Updated 2 days ago

Matomo on FrankenPHP with unattended setup, GeoIP, Redis/Valkey cache and Kubernetes support

Image
0

8.8K

ideaplexus/matomo repository overview

⁠ideaplexus/matomo

Matomo⁠ as a single container image, ready for Docker Compose and Kubernetes:

  • FrankenPHP (Caddy with embedded PHP 8.5) on Alpine 3.24, no PHP-FPM, no process supervisor
  • Unattended setup: configuration from environment variables, installation without the web installer, database migrations on start
  • Kubernetes: Deployments and StatefulSets, with or without a shared volume, init jobs, archiving CronJob, read-only root filesystem, no capabilities, non-root
  • GeoIP providers: DB-IP, MaxMind, any GeoIP2 compatible download or file, Cloudflare and CloudFront headers
  • Redis/Valkey as shared cache
  • Plugins from the Marketplace, bundled into the image or installed on start
cp .env.example .env    # set the passwords and the salt: openssl rand -hex 32
docker compose up -d
open http://localhost:8080

⁠Contents

⁠Design

⁠Web server
OptionProcessesProsCons
FrankenPHP (Caddy + embedded PHP) ✅1No FPM, no supervisor; automatic HTTPS, HTTP/2+3, zstd/br; configured with environment placeholders; official image with install-php-extensionsYounger project; thread-safe (ZTS) PHP; Matomo only runs in classic mode, not in worker mode
Caddy + PHP-FPM2Mature FPM, Caddy featuresNeeds a supervisor (s6, supervisord) or two containers sharing the code
nginx + PHP-FPM2Configuration documented by Matomo (matomo-nginx⁠)Needs a supervisor, no automatic TLS
Apache + mod_php (official matomo:apache)1Matomo's .htaccess protection works as isHeavyweight (prefork), TLS needs another component

The access rules of matomo-nginx are ported to rootfs/etc/caddy/Caddyfile⁠: only the Matomo entry points are executed, internal directories are blocked, code directories serve static assets only.

⁠Base image
  • Bitnami is no option: its free images moved to bitnamilegacy/* in August 2025 and receive no updates.
  • The official matomo image copies the code into a volume on the first start, which makes updates through a new image cumbersome, and Docker Hub lags behind the Matomo releases.
  • This image uses the same source as the official one (the release archive from builds.matomo.org, verified with the Matomo signing key), but keeps the code immutable in /app. A new Matomo version is a new image.
⁠Layout
/app                        Matomo (part of the image, owned by root)
  bootstrap.php             moves PIWIK_USER_PATH and the plugin directory to /var/lib/matomo
  plugins/ContainerSetup    console commands for configuration, installation, plugins and GeoIP
/etc/matomo                 optional configuration of the user (read-only, eg. a ConfigMap)
  conf.d/*.ini              INI settings
  config.php                DI definitions
/var/lib/matomo             all state (volume), the only writable path
  config/                   config.ini.php, common.config.ini.php and config.php
  tmp/                      caches, compiled templates, sessions of PHP
  geoip/                    GeoIP databases (.mmdb)
  plugins/                  plugins installed from the Marketplace
  js/, tagmanager/          generated tracker and Tag Manager containers
  misc-user/                custom logos
  caddy/                    Caddy state (certificates with automatic HTTPS)

The container runs as www-data (UID/GID 82), Caddy listens on 8080 (and 8443 with automatic HTTPS).

⁠Start

matomo-entrypoint runs before the web server starts:

  1. writes common.config.ini.php and config.php (see configuration⁠)
  2. container:configure: waits for the database, creates it if missing, detects the charset
  3. container:init, under a database lock, so containers starting at the same time never install twice or migrate concurrently:
    • installation without the web installer: tables, super user, first website
    • core:update: database migrations after a version change; settings the migrations write to config.ini.php are recorded in the database and copied into the config.ini.php of every container
    • Marketplace license, GeoIP configuration
    • plugins of this container: Marketplace downloads (again, if the installed version does not support the Matomo version), installation state, activation
  4. container:prepare: GeoIP database download, tracker and Tag Manager files of this container
  5. FrankenPHP

MATOMO_INIT selects how much of this a container does:

MATOMO_INIT
full (default)everything
configurewaits until another container or a job has installed Matomo, then only the plugins of this container (step 3, under the lock) and step 4
nonenothing, the data directory is provided completely

Other commands of the image:

Command
initthe initialisation only, then exit (Kubernetes init container or job)
archivecore:archive every MATOMO_ARCHIVE_INTERVAL seconds, once with 0 (Kubernetes CronJob)
console <command>a Matomo console command
matomo-plugin-downloadbundles Marketplace plugins in derived images, see plugins⁠

⁠Configuration

Matomo merges three INI files. The container generates the first one on every start, Matomo writes the second:

PrecedenceSourceWritten to
1 (lowest)container defaults (logs to stderr, no one-click update, ...)common.config.ini.php
2/etc/matomo/conf.d/*.ini and *.ini.php, alphabeticalcommon.config.ini.php
3environment variables below, MATOMO_CONFIG__<Section>__<key>common.config.ini.php
4 (highest)Matomo itself: generated salt, installation state, plugins, changes in the UIconfig.ini.php

Because common.config.ini.php is regenerated, removing a variable or file takes effect on the next start. DI definitions in /etc/matomo/config.php (returning an array) are merged into Matomo's config.php.

Every variable can also be read from a file with the suffix _FILE, eg. MATOMO_DATABASE_PASSWORD_FILE.

⁠Database and installation
VariableDefaultDescription
MATOMO_DATABASE_HOST–Without host the Matomo web installer is used
MATOMO_DATABASE_PORT3306
MATOMO_DATABASE_USERNAME, _PASSWORD, _DBNAME–The database is created if it does not exist and the user may
MATOMO_DATABASE_TABLES_PREFIXempty
MATOMO_DATABASE_ADAPTERPDO\MYSQLor MYSQLI
MATOMO_DATABASE_SCHEMAMysqlMariadb enables MariaDB specific features
MATOMO_DATABASE_WAIT_TIMEOUT120Seconds to wait for the database
MATOMO_SALTgeneratedSet it if the data volume is not persistent or not shared by all containers, sessions and tokens depend on it
MATOMO_AUTO_INSTALLtruefalse: finish the installation in the browser
MATOMO_AUTO_UPDATEtrueRun core:update on start
MATOMO_ADMIN_USER, _PASSWORD, _EMAIL–Required for the unattended installation
MATOMO_SITE_NAME, _URL, _TIMEZONE, _CURRENCY, _ECOMMERCEWebsite, MATOMO_URL, UTC, EUR, falseFirst website
MATOMO_INITfullSee start⁠
MATOMO_INIT_LOCK_TIMEOUT600Seconds to wait for the initialisation lock
MATOMO_INSTALL_WAIT_TIMEOUT600Seconds MATOMO_INIT=configure waits for the installation
⁠General
VariableDefaultDescription
MATOMO_URL–Public URL, sets trusted_hosts and the URL used on the command line
MATOMO_TRUSTED_HOSTShost of MATOMO_URLComma separated. With MATOMO_PROXY_HOST_HEADERS list the public hostname and the hostname the proxy connects to: Matomo 6 checks the public one, and caches the tracker configuration only for a trusted Host header
MATOMO_PROXY_CLIENT_HEADERS–eg. HTTP_X_FORWARDED_FOR behind an ingress
MATOMO_PROXY_HOST_HEADERS, _SCHEME_HEADERS, MATOMO_PROXY_IPS–Comma separated
MATOMO_ASSUME_SECURE_PROTOCOL, MATOMO_FORCE_SSL–true/false
MATOMO_BROWSER_ARCHIVING–false when an archiver runs
MATOMO_MULTI_SERVERfalsetrue for several containers without a shared volume, see Kubernetes⁠
MATOMO_CONFIG__<Section>__<key>–Any INI setting, eg. MATOMO_CONFIG__mail__host=smtp.example.org. Values starting with [ are JSON arrays
MATOMO_ARCHIVE_INTERVAL3600Command archive: seconds between runs, 0 for a single run
MATOMO_ARCHIVE_OPTIONS–Additional core:archive options, eg. --concurrent-requests-per-website=3
⁠Cache

With more than one container, Matomo needs a shared cache: with the default file cache every container keeps its own copy and misses the invalidations of the others (new websites, changed settings, ...).

VariableDefaultDescription
MATOMO_REDIS_HOST–Enables Redis/Valkey as cache (array + redis chain). tls://host for TLS
MATOMO_REDIS_PORT6379
MATOMO_REDIS_UNIX_SOCKET–Instead of host and port
MATOMO_REDIS_PASSWORD–
MATOMO_REDIS_DATABASE14Use another database for QueuedTracking
MATOMO_REDIS_TIMEOUT1.0Seconds

Valkey and Redis are both supported, the entries are serialized with igbinary.

⁠Web server and PHP
VariableDefaultDescription
SERVER_NAME:8080A hostname (analytics.example.org) enables automatic HTTPS on 8443, redirect on 8080
CADDY_HTTP_PORT, CADDY_HTTPS_PORT8080, 8443
TRUSTED_PROXIESprivate_rangesProxies Caddy trusts for X-Forwarded-For
CADDY_SERVER_EXTRA_DIRECTIVES–eg. log for access logs
CADDY_GLOBAL_OPTIONS, FRANKENPHP_CONFIG–eg. FRANKENPHP_CONFIG="num_threads 32"
PHP_MEMORY_LIMIT512MAlso used by the archiving
PHP_MAX_EXECUTION_TIME, PHP_UPLOAD_MAX_FILESIZE, PHP_POST_MAX_SIZE, PHP_OPCACHE_MEMORY300, 64M, 64M, 256

/healthz is answered by Caddy without PHP (liveness), /matomo.php by PHP (readiness).

⁠Plugins

WaySurvives a new containerSeveral containers without shared volumeVersions
Bundled in the image: build argument MATOMO_PLUGINS or a derived imageyesyespinned
MATOMO_PLUGINS_INSTALLdownloaded again if the volume is not persistentevery container downloads itlatest compatible at the time of the download
Marketplace in the UIwith a persistent volumeno, disabled by MATOMO_MULTI_SERVERlatest compatible

A derived image pins versions, so all containers run the same code (free plugins):

FROM ideaplexus/matomo:6.0.0
USER root
RUN matomo-plugin-download [email protected] LoginLdap
USER 82:82
VariableDescription
MATOMO_PLUGINS_INSTALLComma separated Marketplace plugins, downloaded into the data directory if missing or if the installed version does not support the Matomo version (eg. after the update to Matomo 6), and activated. Premium plugins need the license key
MATOMO_PLUGINS_ACTIVATE, MATOMO_PLUGINS_DEACTIVATEComma separated plugins, applied on every start
MATOMO_MARKETPLACE_LICENSE_KEYLicense for premium plugins

The activation state lives in config.ini.php. Every container applies the variables itself under the initialisation lock, so containers without a shared volume end up with the same plugins. Plugins activated in the UI are only known to containers sharing the data volume.

Installing from the Marketplace in the UI needs a writable root filesystem: Matomo insists on a writable /app/plugins, although it stores the plugin in the data directory. MATOMO_PLUGINS_INSTALL works with a read-only root filesystem.

⁠GeoIP

Two independent settings: where the location comes from (MATOMO_GEOIP_PROVIDER) and which database is provided (MATOMO_GEOIP_DATABASE, also the fallback of the header providers, eg. for log imports). The PHP extension maxminddb speeds up all database lookups.

MATOMO_GEOIP_PROVIDERSource
database (default)MMDB database, Matomo provider "GeoIP 2 (PHP)"
cloudflareCF-IPCountry; city, region and coordinates need the Cloudflare managed transform "Add visitor location headers". Sets proxy_client_headers to CF-Connecting-IP unless configured
cloudfrontCloudFront-Viewer-*, add the headers to the origin request policy
headersCustom headers via MATOMO_GEOIP_HEADER_<KEY> (COUNTRY_CODE, REGION_CODE, CITY_NAME, LATITUDE, LONGITUDE, POSTAL_CODE, CONTINENT_CODE, ...), also overrides the presets
defaultNo geolocation (Matomo guesses the country from the browser language)
manualNothing is changed, configure it in the Matomo UI

The header providers map the CDN headers in Caddy to the $_SERVER variables of the Matomo provider "GeoIP 2 (HTTP server module)", only for requests from MATOMO_GEOIP_TRUSTED_PROXIES (default private_ranges). Set the IP ranges of the CDN if it connects directly, otherwise countries can be forged.

MATOMO_GEOIP_DATABASEVariables
dbip (default)MATOMO_GEOIP_DBIP_EDITION=city|country, MATOMO_GEOIP_DBIP_ASN=true for provider data. Free, no account (CC BY 4.0, attribution required)
maxmindMATOMO_GEOIP_MAXMIND_LICENSE_KEY (required), MATOMO_GEOIP_MAXMIND_EDITION (GeoLite2-City), MATOMO_GEOIP_MAXMIND_ISP_EDITION (eg. GeoLite2-ASN). Matomo logs the download URL including the license key
urlMATOMO_GEOIP_LOC_URL, MATOMO_GEOIP_ISP_URL, eg. paid DB-IP downloads. The host must be in geolocation_download_from_trusted_hosts (maxmind.com, db-ip.com, ip2location.com)
fileMount the .mmdb files to /var/lib/matomo/geoip/ with Matomo's file names (eg. GeoIP2-City.mmdb)
noneNo database
VariableDefaultDescription
MATOMO_GEOIP_UPDATE_PERIODmonthweek or month, updates by the Matomo scheduler (runs with the archiving)
MATOMO_GEOIP_DOWNLOAD_ON_STARTmissingmissing (also when older than the maximum age), always, never
MATOMO_GEOIP_MAX_AGE_DAYS35Containers without a shared volume refresh their databases on start, the scheduler only updates its own container

⁠Kubernetes

A Helm chart is developed separately. The image supports these topologies:

TopologyData volumeNotes
Single replica (Deployment or StatefulSet)ReadWriteOnce PVCEverything works like with Compose
Replicas with shared volumeReadWriteMany PVC, mounted by all pods and the CronJobPlugins and settings from the UI apply to all pods, the scheduler updates GeoIP for all
Replicas without shared volumeemptyDir, or a ReadWriteOnce PVC per pod of a StatefulSetSet MATOMO_SALT and MATOMO_MULTI_SERVER=true; manage plugins with variables or the image

Every topology with more than one pod needs MATOMO_REDIS_HOST and MATOMO_SALT.

Without a shared volume each pod has its own config.ini.php, plugin directory, GeoIP databases and Tag Manager files:

  • MATOMO_MULTI_SERVER=true sets Matomo's multi_server_environment and disables the plugin administration in the UI, changes there would only reach one pod
  • every pod applies MATOMO_PLUGINS_* and regenerates the Tag Manager containers on start; a container published in the UI reaches the other pods with their next start
  • GeoIP databases are downloaded on start and refreshed after MATOMO_GEOIP_MAX_AGE_DAYS
⁠Initialisation
  • All pods with MATOMO_INIT=full (default): the first pod installs or migrates, the others wait for the lock and continue. Rolling updates migrate with the first new pod.
  • Init job + pods with MATOMO_INIT=configure: a Helm hook job runs the image with the command init, the pods wait for the installation and only set up their own plugins.
⁠Archiving

A CronJob runs the image with the command archive and MATOMO_ARCHIVE_INTERVAL=0: one core:archive run, then exit. Use concurrencyPolicy: Forbid. It needs the same database, cache and plugin variables as the pods and MATOMO_SALT, it writes its own configuration unless it mounts the shared volume. Set MATOMO_BROWSER_ARCHIVING=false on the pods.

⁠Pod settings
securityContext:            # pod
  runAsNonRoot: true
  runAsUser: 82
  runAsGroup: 82
  fsGroup: 82
  seccompProfile:
    type: RuntimeDefault
containers:
  - name: matomo
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true   # false only for Marketplace installs in the UI
      capabilities:
        drop: [ALL]
    ports:
      - containerPort: 8080
    volumeMounts:
      - name: data                   # the only writable path
        mountPath: /var/lib/matomo
      - name: config                 # optional ConfigMap with *.ini files
        mountPath: /etc/matomo/conf.d
    startupProbe:                    # the first start installs and downloads GeoIP databases
      httpGet: {path: /matomo.php, port: 8080}
      periodSeconds: 10
      failureThreshold: 60
    readinessProbe:
      httpGet: {path: /matomo.php, port: 8080}
    livenessProbe:
      httpGet: {path: /healthz, port: 8080}

The image has no file capabilities, so it runs with capabilities: drop: [ALL]. Behind an ingress set MATOMO_PROXY_CLIENT_HEADERS=HTTP_X_FORWARDED_FOR, MATOMO_ASSUME_SECURE_PROTOCOL=true and MATOMO_URL.

⁠PHP extensions

Included besides the extensions of the PHP image: bcmath, gd (graphs), igbinary (Redis cache serialization), ldap (LoginLdap), maxminddb (GeoIP), mysqli, opcache, pdo_mysql, redis (cache, QueuedTracking), zip (plugin installation). Matomo's system check reports no missing extension.

Deliberately not included:

ExtensionWhy
imagickMatomo uses GD for its graphs, only the PDF library could use it for images in PDF reports; adds ImageMagick with a long security history
apcuNot used by Matomo (the official image installs it anyway)
intlMatomo ships its own locale data
pdo_pgsqlMatomo 5 only supports MySQL and MariaDB

Add an extension in a derived image with install-php-extensions <name> as root. The log analytics importer (misc/log-analytics) is a Python script and runs better outside this image.

⁠Databases

Matomo 6 requires MySQL 8.0+ or MariaDB 10.6+ (Matomo 5: MySQL 5.5+ or MariaDB); it publishes no list of supported MariaDB versions. Compose and the tests use MariaDB 12.3, the current long-term support series (maintained until 2029). Renovate only proposes LTS series (x.3), the rolling releases in between are supported for a few months only. The smoke test also passes against MariaDB 11.8 and 13.0.

⁠Tags and Matomo versions

TagExampleChanges
<Matomo version>-<revision>5.14.1-2never, one image release
<Matomo version>, <major>.<minor>, <major>5.14.1, 5.14, 5with every release of that Matomo version or line
latestwith every release of the current Matomo major
edgewith every build of the default branch, only in Harbor
<major>-edge5-edgewith every build of a maintenance branch, only in Harbor

The revision counts the releases of one Matomo version and starts at 1 again with a new Matomo version: 5.14.1-1, 5.14.1-2, then 5.15.0-1. Docker tags cannot carry SemVer build metadata (5.14.1+1), hence the hyphen. Pin a release, eg. as appVersion of a Helm chart.

:latest and :6 follow Matomo 6. Matomo 5 stays supported as LTS until 23 November 2027, and so does its image: :5, :5.14 and 5.14.3-<revision> get its releases and the security updates of the base image. Pin :5 (or a release) to stay on Matomo 5: a container on :latest updates the database on its next start.

The update from 5 to 6:

  • Back up the database first. The migrations cannot be undone, the only way back is the backup. They add a column to log_visit, which takes a while on a large installation.
  • It needs MySQL 8.0+ or MariaDB 10.6+. PHP is part of the image.
  • container:init runs it once, under the initialisation lock: replicas starting at the same time wait, then find the database up to date. Old containers keep running during a rolling update; stop them first if the log_visit change takes long.
  • Matomo 6 keeps the hierarchical Actions archiving of an existing installation (datatable_archiving_maximum_rows_actions_flat = 0 in config.ini.php), only new installations archive flat. The container records the setting in the database, so replicas without shared volume, the archiver CronJob and every later pod keep it too. Set MATOMO_CONFIG__General__datatable_archiving_maximum_rows_actions_flat to switch.
  • Third-party plugins need a version for Matomo 6, Matomo deactivates the others. MATOMO_PLUGINS_INSTALL replaces them by a compatible version from the Marketplace, as soon as there is one. Rebuild derived images with versions for Matomo 6; plugins installed in the UI are updated in the UI.
  • With MATOMO_PROXY_HOST_HEADERS, the hostname from the proxy header has to be trusted, see MATOMO_TRUSTED_HOSTS.

⁠Development

Tests, pipeline, releases, Renovate and the changelog: see DEVELOPMENT.md⁠.

Tag summary

Content type

Image

Digest

sha256:582cab44d…

Size

125.5 MB

Last updated

2 days ago

docker pull ideaplexus/matomo