Nextcloud really slow after installation

I installed Nextcloud using Docker/docker-compose with mariadb. After I finally got the connection to the database working I noticed that the webinterface is really slow, like unusably slow. Its running on a VM with 4GB RAM and 2 virtual CPUs, so that shouldnt be the problem. RAM and CPU usage is also quite low.
I was thinking that this may be an issue with the database as there are also some warnings in the admin panel.

This is my docker-compose.yml

version: '3'

volumes:
  nextcloud:
  db:

services:
  nextcloud_mariadb:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    volumes:
      - /home/user/nextcloud/db:/var/lib/mysql
      - /home/user/nextcloud/my.cnf:/etc/mysql/my.cnf
    environment:
      - MYSQL_ROOT_PASSWORD='xxx'
      - MYSQL_PASSWORD='xxx'
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    ports:
      - 3306:3306
    networks:
      - nextcloud

  nextcloud:
    image: nextcloud:fpm
    links:
      - nextcloud_mariadb
    volumes:
      - /home/user/mnt/VM-Data/nextcloud:/var/www/html
    restart: always
    ports:
      -  9000:9000
    networks: 
      - nextcloud 
  nextcloud_nginx:
    image: nginx
    ports:
      - 8082:80
    links:
      - nextcloud
    volumes:
      - /home/user/nextcloud/nginx.conf:/etc/nginx/nginx.conf:ro
      - /home/user/mnt/VM-Data/nextcloud:/var/www/html:ro
    restart: always
    networks:
      - nextcloud
  

And these are the warning in the admin panel:
(Sorry its german I didnt manage to change it. I trnaslated parts of it.

    Some indeces are missing from the databse. They were not added automatically because that takes too much time Run "occ db:add-missing-indices" to add them. After that the database should be faster
        missing index "calendarobject_calid_index" in table "oc_calendarobjects_props".
        missing index "schedulobj_principuri_index" in table "oc_schedulingobjects".

Some colums are missing a conversion to big int. Aufgrund der Tatsache, dass das Ändern von Spaltentypen bei großen Tabellen einige Zeit dauern kann, wurden sie nicht automatisch geändert. Run "occ db:convert-filecache-bigint" können diese ausstehenden Änderungen manuell übernommen werden. Diese Operation muss ausgeführt werden, während die Instanz offline ist. Weitere Einzelheiten findest Du auf der zugehörigen Dokumentationsseite.
        mounts.storage_id
        mounts.root_id
        mounts.mount_id

However I cant run occ because of an issue with the filesystem with docker.

# php occ db:add-missing-indices
Console has to be executed with the user that owns the file config/config.php
Current user: root
Owner of config.php: 
Try adding 'sudo -u  ' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u ' to the docker command (without the single quotes)

The file doesnt seem to have an owner. Thats also why i cant just use sudo -u This is ls inside the container:

# ls -l
total 105
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:09 3rdparty
-rwxrwxrwx 1 899 nogroup 15752 Feb 25 14:08 AUTHORS
-rwxrwxrwx 1 899 nogroup 34520 Feb 25 14:08 COPYING
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:11 apps
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:24 config
-rwxrwxrwx 1 899 nogroup  3910 Feb 25 14:08 console.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:11 core
-rwxrwxrwx 1 899 nogroup  5048 Feb 25 14:08 cron.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:22 custom_apps
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:36 data
-rwxrwxrwx 1 899 nogroup   156 Feb 25 14:08 index.html
-rwxrwxrwx 1 899 nogroup  2976 Feb 25 14:08 index.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 lib
-rwxrwxrwx 1 899 nogroup   283 Feb 25 14:08 occ
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 ocm-provider
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 ocs
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 ocs-provider
-rwxrwxrwx 1 899 nogroup  3056 Feb 25 14:08 public.php
-rwxrwxrwx 1 899 nogroup  5235 Feb 25 14:08 remote.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 resources
-rwxrwxrwx 1 899 nogroup    26 Feb 25 14:08 robots.txt
-rwxrwxrwx 1 899 nogroup  2381 Feb 25 14:08 status.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 themes
-rwxrwxrwx 1 899 nogroup   362 Feb 25 14:12 version.php

and this is ls on the host where the www folder is mapped using a bind-mount (see docker-compose). The dolder is mounted onto the Host with samba

alpine:~/mnt/VM-Data/nextcloud$ ls -l
total 105
drwxrwxrwx    2 user     users            0 Feb 25 15:09 3rdparty
-rwxrwxrwx    1 user     users        15752 Feb 25 15:08 AUTHORS
-rwxrwxrwx    1 user     users        34520 Feb 25 15:08 COPYING
drwxrwxrwx    2 user     users            0 Feb 25 15:11 apps
drwxrwxrwx    2 user     users            0 Feb 25 15:24 config
-rwxrwxrwx    1 user     users         3910 Feb 25 15:08 console.php
drwxrwxrwx    2 user     users            0 Feb 25 15:11 core
-rwxrwxrwx    1 user     users         5048 Feb 25 15:08 cron.php
drwxrwxrwx    2 user     users            0 Feb 25 15:22 custom_apps
drwxrwxrwx    2 user     users            0 Feb 25 15:36 data
-rwxrwxrwx    1 user     users          156 Feb 25 15:08 index.html
-rwxrwxrwx    1 user     users         2976 Feb 25 15:08 index.php
drwxrwxrwx    2 user     users            0 Feb 25 15:12 lib
-rwxrwxrwx    1 user     users          283 Feb 25 15:08 occ
drwxrwxrwx    2 user     users            0 Feb 25 15:12 ocm-provider
drwxrwxrwx    2 user     users            0 Feb 25 15:12 ocs
drwxrwxrwx    2 user     users            0 Feb 25 15:12 ocs-provider
-rwxrwxrwx    1 user     users         3056 Feb 25 15:08 public.php
-rwxrwxrwx    1 user     users         5235 Feb 25 15:08 remote.php
drwxrwxrwx    2 user     users            0 Feb 25 15:12 resources
-rwxrwxrwx    1 user     users           26 Feb 25 15:08 robots.txt
-rwxrwxrwx    1 user     users         2381 Feb 25 15:08 status.php
drwxrwxrwx    2 user     users            0 Feb 25 15:12 themes
-rwxrwxrwx    1 user     users          362 Feb 25 15:12 version.php

Are the missing indexes really the problem? And if so how can I fix the permissions inside the container? (chown doesnt work)

Have you optimized your configuration in Nextcloud?
https://docs.nextcloud.com/server/18/admin_manual/installation/server_tuning.html

most of the things are already configured. For example http2 or memory caching.
I couldnt find the www.conf file for php-fpm tuning. I looked in the nextcloud app container and the nginx container.

I ran iotop however and it seems that its definatly an issue with a configuration there is no bottleneck on reads/writes or cpu/ram usage.

Do you have an idea on how to fix the permission issue with occ?

You must start “occ” with the webserver/nextcloud-user:

sudo -u www-data occ ...
(i think sudo is correct configured throw nextcloud-installation)

That doesnt work as the www-data user doesnt own occ. Noone owns the file. This is a problem with docker that I couldnt manage to fix so far.

root@780ff3289924:/var/www/html# sudo -u www-data php occ db:add-missing-indices
Console has to be executed with the user that owns the file config/config.php
Current user: www-data
Owner of config.php: 
Try adding 'sudo -u  ' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u ' to the docker command (without the single quotes)