Giter Club home page Giter Club logo

docker-matomo's Introduction

Version Build Status Docker Stars Docker Pulls Docker Repository on Quay Code Quality Donate Paypal

About

๐Ÿณ Matomo (formerly Piwik) Docker image based on Alpine Linux and Nginx.
If you are interested, check out my other ๐Ÿณ Docker images!

Features

Included

  • Alpine Linux 3.9, Nginx, PHP 7.2
  • Tarball authenticity checked during building process
  • Config, plugins and user preferences in the same folder
  • GeoIP 2 databases created by MaxMind for geolocation
  • Unifont for languages using unicode characters
  • Cron tasks to archive Matomo reports and update GeoIP 2 databases as a "sidecar" container
  • Ability to pass additional options during cron archive
  • Plugins and config are kept across upgrades of this image
  • SSMTP for SMTP relay to send emails
  • OPCache enabled to store precompiled script bytecode in shared memory
  • Redis enabled and ready to enhance server performance

From docker-compose

Docker

Environment variables

  • TZ : The timezone assigned to the container (default UTC)
  • MEMORY_LIMIT : PHP memory limit (default 256M)
  • UPLOAD_MAX_SIZE : Upload max size (default 16M)
  • OPCACHE_MEM_SIZE : PHP OpCache memory consumption (default 128)
  • REAL_IP_FROM : Trusted addresses that are known to send correct replacement addresses (default 0.0.0.0/32)
  • REAL_IP_HEADER : Request header field whose value will be used to replace the client address (default X-Forwarded-For)
  • LOG_IP_VAR : Use another variable to retrieve the remote IP address for access log_format on Nginx. (default remote_addr)
  • LOG_LEVEL : Log level of Matomo UI (default WARN)
  • SIDECAR_CRON : Mark the container as a sidecar cron job (default 0)
  • SSMTP_HOST : SMTP server host
  • SSMTP_PORT : SMTP server port (default 25)
  • SSMTP_HOSTNAME : Full hostname (default $(hostname -f))
  • SSMTP_USER : SMTP username
  • SSMTP_PASSWORD : SMTP password
  • SSMTP_TLS : SSL/TLS (default NO)

The following environment variables are only used if you run the container as "sidecar" mode :

  • SIDECAR_CRON : Set to 1 to enable sidecar cron mode (default 0)
  • ARCHIVE_OPTIONS : Pass additional options during cron archive
  • CRON_GEOIP : Periodically update GeoIP 2 databases (disabled if empty ; eg. 0 4 * * *)
  • CRON_ARCHIVE : Periodically execute Matomo archive (disabled if empty ; ex 0 * * * *)

Volumes

  • /data : Contains GeoIP 2 databases, configuration, installed plugins (not core ones), tmp and user folders to store your custom logo

Ports

  • 8000 : HTTP port

Use this image

Docker Compose

Docker compose is the recommended way to run this image. Copy the content of folder examples/compose in /var/matomo/ on your host for example. Edit the compose and env files with your preferences and run the following commands :

touch acme.json
chmod 600 acme.json
docker-compose up -d
docker-compose logs -f

Swarm

Deploy this image in your Swarm cluster. Detailed instructions can be found here.

Kubernetes

Deploy this image in your kubernetes cluster. Detailed instructions can be found here.

Command line

You can also use the following minimal command :

docker run -d -p 8000:8000 --name matomo \
  -v $(pwd)/data:/data \
  crazymax/matomo:latest

Notes

Sticky sessions

On a HA environment, enable backend sticky sessions on your load balancer.

Cron

If you want to enable the cron job, you have to run a "sidecar" container like in the docker-compose file or run a simple container like this :

docker run -d --name matomo_cron \
  --env-file $(pwd)/matomo.env \
  -e "SIDECAR_CRON=1" \
  -e "CRON_ARCHIVE=0 * * * *" \
  -e "ARCHIVE_OPTIONS=--concurrent-requests-per-website=3" \
  -v $(pwd)/data:/data \
  crazymax/matomo:latest

Then if you have enabled CRON_ARCHIVE to automatically archive the reports, you have to disable Matomo archiving to trigger from the browser. Go to System > General settings :

Disable Matomo archiving from browser

GeoIP 2

This image already uses GeoIP 2 databases of MaxMind through Nginx. You just have to install and activate the GeoIP 2 plugin.

After that, you have to select GeoIP 2 (HTTP Server Module) in System > Geolocation :

GeoIP 2 location provider

And activate GeoIP 2 server module for Nginx in System > General settings > Configuration for server variables used by GeoIP 2 server modules :

GeoIP 2 server module

โš ๏ธ GeoIP (Legacy) is now deprecated and has been removed since 3.8.0 tag.

Behind a reverse proxy ?

If you are running Matomo behind a reverse proxy, add this to your config.ini.php :

[General]
assume_secure_protocol = 1 # 0=http 1=https
proxy_client_headers[] = HTTP_X_FORWARDED_FOR
proxy_client_headers[] = HTTP_X_REAL_IP
proxy_host_headers[] = HTTP_X_FORWARDED_HOST

Redis cache

To use Redis as a cache (useful if your Matomo environment consists of multiple servers), add this to your config.ini.php :

[Cache]
backend = chained

[ChainedCache]
backends[] = array
backends[] = redis

[RedisCache]
host = "redis" # Docker service name for Redis 
port = 6379
timeout = 0.0
password = ""
database = 14

In case you are using queued tracking: Make sure to configure a different database! Otherwise queued requests will be flushed.

Plugins

If you are on a HA environment, there is no need to set multi_server_environment = 1 in your config.
matomo_watch_plugins script will take care of plugins synchronization from /data/plugins/ to /var/www/plugins/.

Upgrade

You can upgrade Matomo automatically through the UI, it works well. But I recommend to recreate the container whenever I push an update :

docker-compose pull
docker-compose up -d

How can I help ?

All kinds of contributions are welcome ๐Ÿ™Œ!
The most basic way to show your support is to star ๐ŸŒŸ the project, or to raise issues ๐Ÿ’ฌ
But we're not gonna lie to each other, I'd rather you buy me a beer or two ๐Ÿป!

Paypal

License

MIT. See LICENSE for more details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.