No permission to upload or change anything. Docker

docker-compose.yaml:

version: '3'

services:
  db:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: unless-stopped
    volumes:
      - db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=XXX
      - MYSQL_PASSWORD=YYY
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  next:
    container_name: nextcloud
    image: nextcloud
    expose:
      - "80"
    links:
      - db
    volumes:
      - nextcloud:/var/www/html
      - /media/disk1/nextcloud:/var/www/html/data

    environment:
      - TZ=Europe/Stockholm
    networks:
      - proxy-net
      - default
    restart: unless-stopped
    labels:
      - "traefik.docker.network=proxy-net"
      - "traefik.enable=true"
      - "traefik.frontend.auth.basic"
      - "traefik.basic.frontend.rule=Host:next.DOMAIN.com"
      - "traefik.basic.port=80"

networks:
  proxy-net:
    external: true

volumes:
  nextcloud:
  db:

Nextcloud version (eg, 12.0.2): 16.0.3
Operating system and version (eg, Ubuntu 17.04): Ubuntu 19.04
PHP version (eg, 7.1): 7.2.19

I am running nexcloud in docker, im pretty new with both docker and nextcloud it but it seems to work for the most part. I sometimes get this error that I dont have permission to upload or create files anywhere from my admin account. I have tried to re-create the container only to be forced to “complete installation” again and having to create a new admin account with all my media not being found.

/media/disk1 is mounted as ext4 and its the same disk I got plex media on.

I have tried to rescan everything with “sudo -u www-data php occ files:scan --all” but Im not quite sure where to run it from. Running it from /var/lib/docker/volumes/nextcloud_nextcloud/_data where occ is gives me the error “console.php: failed to open stream: permission denied”.
Running it from /media/disk1/nextcloud/ gives the error “could not open input file: occ”.

config.php:

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'instanceid' => 'XXX',
  'passwordsalt' => 'YYY',
  'secret' => 'XXX',
  'trusted_domains' =>
  array (
    0 => 'next.DOMAIN.com',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'sqlite3',
  'version' => '16.0.3.0',
  'overwrite.cli.url' => 'http://next.DOMAIN.com',
  'installed' => true,
);

this folder must have the same user/group id than the user www-data in the nextcloud container. simply run

sudo docker exec -u www-data nextcloud id

with the given uid= and gid= (not “www-data” because on your host it might not exist.) you run:

sudo chown <uid>:<gid> /media/disk1/nextcloud

in my case it’s
sudo chown 82:82 /media/disk1/nextcloud

and make sure that this ownership is not lost after reboot/remount of disk1.

you run it inside the container:
sudo docker exec -u www-data nextcloud php occ files:scan --all

Thanks alot! The permission issue dissapeared by itself for some reason, without me doing anything. But atleast I can change permission and rescan manually now. Thanks!