Unable to write in the cache directory (/var/www/html/tmp/templates_c/29)

Hi all, after updating to 5.2.2 I receive the error:

Unable to write in the cache directory (/var/www/html/tmp/templates_c/29)

I can solve the error by changing the ownership of all files in templates_c from root to www-data. But every following day, the error reappears.
I am running Matomo in docker using the official image.
Does anybody know a solution to this? See directory contents and compose.yml below.
Thanks in advance!

root@90ad4f89b9f8:/var/www/html/tmp# ls -l
drwxr-x--- 2 www-data www-data 16384 Feb 24 07:49 assets
drwxr-x--- 3 www-data www-data  4096 Jul  8  2024 cache
-rw-r--r-- 1 www-data www-data    20 Feb 19 05:06 caseSensitivityTest.txt
drwxr-x--- 2 www-data www-data  4096 Feb 24 08:00 climulti
-rw-r--r-- 1 www-data www-data     4 Feb  6 08:12 empty
-rw-r--r-- 1 www-data www-data    20 Jul  8  2024 index.htm
-rw-r--r-- 1 www-data www-data    20 Jul  8  2024 index.php
drwxr-x--- 3 www-data www-data  4096 Feb 19 05:06 latest
drwxr-x--- 2 www-data www-data  4096 Jul  8  2024 logs
drwxr-x--- 2 www-data www-data  4096 Jul  8  2024 sessions
drwxr-x--- 2 www-data www-data  4096 Jul  8  2024 tcpdf
drwxr-x--- 5 www-data www-data  4096 Feb 24 05:00 templates_c
root@90ad4f89b9f8:/var/www/html/tmp/templates_c# ls -l
drwxr-xr-x 2 root root 4096 Feb 24 05:00 00
drwxr-xr-x 2 root root 4096 Feb 24 05:00 29
drwxr-xr-x 2 root root 4096 Feb 24 05:00 4d
-rw-r--r-- 1 root root   20 Feb 24 04:21 index.htm
-rw-r--r-- 1 root root   20 Feb 24 04:21 index.php
services:
  matomo-db:
    image: mysql:8.4.1
    container_name: matomo-mysql
    volumes:
      - matomo-db:/var/lib/mysql
      - matomo-db-cnf:/etc/mysql/conf.d
    ports:
      - "3306:3306"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}

  matomo-app:
    image: matomo:5.2.2
    container_name: matomo-app
    links:
      - matomo-db
      - matomo-redis
    ports:
      - "9000:80"
    restart: always
    volumes:
      - matomo-app:/var/www/html
    environment:
      MATOMO_DATABASE_HOST: matomo-db
      MATOMO_DATABASE_ADAPTER: mysql
      MATOMO_DATABASE_TABLES_PREFIX: matomo_
      MATOMO_DATABASE_USERNAME: ${MYSQL_USER}
      MATOMO_DATABASE_PASSWORD: ${MYSQL_PASSWORD}
      MATOMO_DATABASE_DBNAME: ${MYSQL_DATABASE}
      PHP_MEMORY_LIMIT: 2G

  matomo-redis:
    image: redis:7.2.5
    container_name: matomo-redis
    command: [ "redis-server", "--requirepass", "${REDIS_PASSWORD}" ]
    ports:
      - "6379:6379"
    volumes:
      - matomo-redis:/data
    restart: always

volumes:
  matomo-db:
  matomo-app:
  matomo-redis:
  matomo-db-cnf: