matomo-org/docker

First time installation: Error in Matomo: Could not connect to the database:

ondics opened this issue · 3 comments

My docker-compose.yml:

  matomo-db:
    image: mariadb:10.9.3
    command: --max-allowed-packet=64MB
    environment:
      - MYSQL_ROOT_PASSWORD=mariadbpass
      - MYSQL_USER=mariadbuser
      - MYSQL_PASSWORD=mariadbpass
      - MYSQL_DATABASE=matomo
      - MATOMO_DATABASE_ADAPTER=mysql
      - MATOMO_DATABASE_TABLES_PREFIX=matomo_
      - MATOMO_DATABASE_USERNAME=mariadbuser
      - MATOMO_DATABASE_PASSWORD=mariadbpass
      - MATOMO_DATABASE_DBNAME=matomo
    volumes:
      - matomo_db:/var/lib/mysql

  matomo-app:
    image: matomo:4.13.3
    volumes:
      - matomo_app:/var/www/html
    environment:
      - MATOMO_DATABASE_HOST=matomo-db
      - PHP_MEMORY_LIMIT=2048M
      - MYSQL_USER=mariadbuser
      - MYSQL_PASSWORD=mariadbpass
      - MYSQL_DATABASE=matomo
      - MATOMO_DATABASE_ADAPTER=mysql
      - MATOMO_DATABASE_TABLES_PREFIX=matomo_
      - MATOMO_DATABASE_USERNAME=mariadbuser
      - MATOMO_DATABASE_PASSWORD=mariadbpass
      - MATOMO_DATABASE_DBNAME=matomo
    ports:
      - "8081:80"
    depends_on:
      - matomo-db

After the installation was done, and I try to login, I get this error in the user interface::

Could not connect to the database:
SQLSTATE[HY000] [1049] Unknown database 'matomo'
This may be a temporary issue, try [refreshing the page](javascript:window.location.reload()). 
Please contact your Matomo administrator if the problem persists

Reload does not help. Sometimes even the login page fails with that message.

The docker logs say:
Error in Matomo: Could not connect to the database: SQLSTATE[HY000] [1049] Unknown database 'matomo' This may be a temporary issue, try refreshing the page. Please contact your Matomo administrator if the problem persists.

How to proceed? Is this a config bug in my docker-compose.yml?

Japhys commented

Did you manage to solve this? I am getting the same error. Using the apache example compose file. Didn't do anything else.

J0WI commented

Are they in the same docker network?

ondics commented

Solved

There are a lot of services in the same network and Traefik is the reverse proxy in that network to control traffic from the outside.

I had to attach add a separate network fort matomo-app and matomo-db matomo and now it works:

matomo-db:
  ...
  networks:
    - traefik
    - matomo

matomo-app:
  ...
  networks:
    - traefik
    - matomo
   
networks:
  traefik:
  matomo: