"Cannot create or write into the data directory" Fedora docker

Hi, so I’ve been trying to create a Nextcloud instance with docker but I’ve been getting the “Cannot create or write into the data directory” error when trying to create an admin account.
I’ve tried to chown the data directory with www, www-data, root, apache but all of them still gave the issue.

The only way I’ve made progress is making every folder nextcloud uses owned by apache but that gives the error after of it can’t read the config directory. Is there any other users I need to try or am I supposed to make a www-data user somehow? Thanks

Please post your Compose file.

version: '3'

services:
  db:
    image: mariadb:10.6
    command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
    restart: always
    volumes:
      - /media/DockerStorage/NextCloud/db:/var/lib/mysql:Z
    environment:
      - MYSQL_ROOT_PASSWORD=
      - MARIADB_AUTO_UPGRADE=1
      - MARIADB_DISABLE_UPGRADE_BACKUP=1
    env_file:
      - .env

  redis:
    image: redis:alpine
    restart: always

  app:
    image: nextcloud:apache
    restart: always
    user: root
    ports:
      - 4377:80
    volumes:
      - /media/DockerStorage/NextCloud/NextCloud:/var/www/html:z
    environment:
      - MYSQL_HOST=db
      - REDIS_HOST=redis
      - SMTP_HOST=
      - SMTP_SECURE=tls
      - SMTP_PORT=587
      - SMTP_NAME=
      - SMTP_PASSWORD=
      - MAIL_FROM_ADDRESS=
      - NEXTCLOUD_DATA_DIR=/media/DockerStorage/NextCloud/Data/
      - APACHE_BODY_LIMIT=21474836480
      - APACHE_DISABLE_REWRITE_IP=0
      - TRUSTED_PROXIES=
      - OVERWRITEPROTOCOL=https
    env_file:
      - .env
    depends_on:
      - db
      - redis

  cron:
    image: nextcloud:apache
    restart: always
    volumes:
      - /media/DockerStorage/NextCloud/NextCloud:/var/www/html:z
    entrypoint: /cron.sh
    depends_on:
      - db
      - redis


I removed sensitive values

   volumes:
      - /media/DockerStorage/NextCloud/NextCloud:/var/www/html:z
    environment:
      [...[
      - NEXTCLOUD_DATA_DIR=/media/DockerStorage/NextCloud/Data/

This says the folder /media/DockerStorage/NextCloud/NextCloud from your host is to be mounted (by Docker not Nextcloud) within the app container as /var/www/html. (That’s fine).

But the NEXTCLOUD_DATA_DIR override (which isn’t necessarily, btw), is telling the app container’s Nextcloud Server installation to use /media/DockerStorage/NextCloud/Data/ as its datadirectory, but that isn’t going to be a valid path (within the container) since it’s a host path.

So the fundamental issue is that your Nextcloud datadirectory is pointed to a non-existent folder (/media/DockerStorage/Nextcloud/Data/) within the app container.

Ah ok, so technically if I wanted to have the Data directory saved to that location, I would need to also add another bind mount to basically the same data directory? So
-/media/DockerStorage/NextCloud/Data/:/media/DockerStorage/NextCloud/Data/