docker icon indicating copy to clipboard operation
docker copied to clipboard

question: an alternative strategy how to use the matomo docker image

Open nflow opened this issue 3 years ago • 15 comments

hey, i have a question regarding an alternative strategy how to use the matomo docker image.

as far as i have observed it, the matomo applicaiton is copied by the entryscript.sh, if the matomo.php is not present, to the /var/www/html folder. since matomo performs various changes to the applicaiton during runtime, e.g. plugins, misc and config. the application folder is mounted externally, to not lose our configuration. the problem with that behavior is that updating a docker image will have no effect on deployments. thats my assessment so far.

in order image updates affect the applicaiton itself i did a few changes. i decided to mount only:

  • /var/www/html/config/config.ini.php
  • /var/www/html/plugins
  • /var/www/html/misc each time i recreate the container all applications will be overwritten with the originals and the update of an image will affect the application itself. furthermore, i prefer to mount relevant configs and folders which make backups more straight forward, in my opinion. i used our current installation in a test setup and switched to the proposed strategy and everything seems to work.

can you think of any issues that may come up doing it this way?

here is the compose file i used:

version: '3.9'

services:
  mysql:
    image: "mariadb"
    command: "--max-allowed-packet=64MB"
    restart: "unless-stopped"
    volumes:
      - "db:/var/lib/mysql"
    environment:
      MYSQL_ROOT_PASSWORD: r00t_p4ssw0rd
      MYSQL_PASSWORD: p4ssw0rd
      MYSQL_DATABASE: matomo
      MYSQL_USER: matomo

  matomo:
    image: "matomo:4.6"
    restart: "unless-stopped"
    volumes:
      - ./configs/php-matomo.ini:/usr/local/etc/php/conf.d/php-matomo.ini:ro
      - ./configs/config.ini.php:/var/www/html/config/config.ini.php
      - plugins:/var/www/html/plugins
      - misc:/var/www/html/misc
    networks:
      - "default" 

volumes:
  db:
  plugins:
  misc:

thanks and kind regards!

nflow avatar Jan 04 '22 14:01 nflow

Thanks, that sounds like a much more sane way to run Matomo in docker.

ulope avatar Feb 03 '22 11:02 ulope

Absolutely what I experienced. I deploy Matomo in a Kubernetes cluster. And made persistent volume claims for all the folders you mentioned. Any hints on why the "entrypoint.sh" script does this copying? Whats the reason for this setup?

hoermannklaus avatar Feb 08 '22 14:02 hoermannklaus

@nflow Can you tell me which files Matomo makes changes to in the misc folder? In my case it seems those files are not changed at all.

djmaze avatar Feb 08 '22 14:02 djmaze

I use the IP2LOCATION plugin. This tells me to put the binary database into the "misc" folder. So I need to persist this folder. Otherwise the database is gone after a Redeploy.

hoermannklaus avatar Feb 08 '22 14:02 hoermannklaus

Any hints on why the "entrypoint.sh" script does this copying? Whats the reason for this setup?

@hoermannklaus See https://github.com/matomo-org/docker/blob/master/Dockerfile-debian.template#L99 and combine that piece of information with https://hub.docker.com/_/matomo:

image

The app matomo itself is not well structured. On the one hand you need /var/www/html to be a volume, to persist runtime changes. On the other hand /var/www/html is supposed to host the app code itself. Hence the solution of OP to dissect app code from persisted runtime changes.

tuky avatar Feb 10 '22 15:02 tuky

This solution would work, weren't it for the anonymous docker volume that gets created automatically (due to the "VOLUME /var/www/html" instruction in the Matomo Dockerfile.

Or aren't you guys using the official image?

ptemmer avatar Feb 17 '22 12:02 ptemmer

When you specify a mounted volume in the compose file (or even on the cli for that matter) with the same target inside the container it overrides the VOLUME command from the dockerfile.

ulope avatar Feb 17 '22 12:02 ulope

But isn't mounting /var/ww/html precisely what we want to avoid? And instead just mount the config, plugins and misc subdirectories?

Thanks!

ptemmer avatar Feb 17 '22 12:02 ptemmer

Ah, yeah of course you're right.

ulope avatar Feb 17 '22 13:02 ulope

@djmaze

Can you tell me which files Matomo makes changes to in the misc folder? In my case it seems those files are not changed at all.

In addition to what is mentioned above, at the very least the Matomo built-in GeoIP2 plugin stores its files there and the custom logo upload feature also puts the images into misc/

Findus23 avatar Feb 17 '22 14:02 Findus23

We're using bitnami's matomo docker image (https://hub.docker.com/r/bitnami/matomo) and we can only suggest you to use it, too. All you need to do here is specify /bitnami/matomo as the volume (see https://github.com/bitnami/bitnami-docker-matomo/blob/master/docker-compose.yml).

tuky avatar Feb 17 '22 15:02 tuky

@tuky, I actually looked into the bitnami container the other day. It's a generic base container where a bunch of scripts (/opt/bitnami/scripts) setup apache, php, the software, etc.. which at first sight adds complexity, especially when trying to debug when something isn't working properly. I'm in two minds about it.

What are your thoughts on that?

ptemmer avatar Feb 17 '22 16:02 ptemmer

We actually acknowledge that as a blackbox, just like matomo's code is a blackbox to us. But we trust in bitnami's competency and looking at the scripts their setup seems well structured. They have a large community and because it's open source we can still dive in, if something breaks. They made rootless work but we use it as root user, because that also runs cron inside the container to periodically run the archiver. It was surprisingly easy to set up a running service using AWS ECS and an EFS for volume persistence.

tuky avatar Feb 17 '22 16:02 tuky

I also think the bitnami approach seems to add much complexity which you need to understand, and I don't really get the benefits. I like containers to be as simple as possible.

The official matomo image works almost perfectly in our swarm mode setup. (Although we needed to increase PHP's memory limit and max execution time, so we derived an image from the official one using a very short dockerfile).

For running, we just assign volumes for the config and plugins folders, because we don't need the geoip stuff. We run an app container and a separate archive container (which runs ./console core:archive --no-interaction and is triggered by cron, or rather swarm-cronjob in our case).

Updating matomo then is as simple as running the update in the web interface and then restarting the containers / services with the updated docker image according to the new version.

djmaze avatar Feb 18 '22 20:02 djmaze

Btw in the end I found https://github.com/crazy-max/docker-matomo works much better.

yi-yang-github avatar Jun 15 '22 20:06 yi-yang-github

Duplicate of https://github.com/matomo-org/docker/issues/248 and https://github.com/matomo-org/matomo/issues/19151. Unfortunately Matomo does not provide a cli to update the application. Just replacing the files may result in a broken database schema.

J0WI avatar Mar 28 '23 12:03 J0WI

It would be really useful if, in addition to closing issues and explaining what doesn't work, you could explain what does work? There's a lot of comments from people on one way or another to do this, and I'm personally left not really understanding how to upgrade Matomo at all.

zofrex avatar Mar 29 '23 21:03 zofrex

https://github.com/matomo-org/docker/issues/248#issuecomment-903618139 is the only supported update mechanism by Matomo.

J0WI avatar Apr 02 '23 13:04 J0WI