Occ command via portainer docker installation

Hello.

i (as 1000 others LOL) need help executing occ via NC in a docker.

I installed NC via Portainer.
I put the following code in stack:

services:
  mariadb:
    container_name: Nextcloud-DB
    image: mariadb:11.4-noble #LTS Long Time Support Until May 29, 2029.
    security_opt:
      - no-new-privileges:false
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --innodb-read-only-compressed=OFF
    volumes:
      - /volume2/docker/nextcloud/db:/var/lib/mysql:rw
      - /volume2/docker/nextcloud/db:/etc/mysql/conf.d:rw
    environment:
      - MYSQL_ROOT_PASSWORD=JustASampleRootPW
      - MYSQL_PASSWORD=JustASampleSQLPW
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - TZ=Europe/Vienna
    restart: on-failure:5
      
  redis:
    image: redis
    container_name: Nextcloud-REDIS
    hostname: nextcloudredis
    user: 1026:100
    healthcheck:
     test: ["CMD-SHELL", "redis-cli ping || exit 1"]
    volumes:
      - /volume2/docker/nextcloud/redis:/data:rw
    environment:
      TZ: Europe/Vienna
    restart: on-failure:5
      
  nextcloud:
    container_name: Nextcloud
    ports:
      - 8082:80
    depends_on:
      mariadb:
       condition: service_started
      redis:
       condition: service_healthy
    environment:
      - REDIS_HOST=nextcloudredis
      - NEXTCLOUD_ADMIN_USER=JustASampleAdminUser
      - NEXTCLOUD_ADMIN_PASSWORD=JustASampleAdminPW
      - NEXTCLOUD_TRUSTED_DOMAINS=Just.a.sampe.domain 192.168.1.6
      - TRUSTED_PROXIES=192.168.1.6
      - OVERWRITEHOST=Just.a.sample.domain
      - OVERWRITEPROTOCOL=https
      - MYSQL_PASSWORD=JustASampleSQLPW
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=mariadb
    healthcheck:
     test: curl -f http://localhost:80/ || exit 1
    volumes:
      - /volume2/docker/nextcloud/html:/var/www/html:rw
      - /volume2/docker/nextcloud/custom_apps:/var/www/html/custom_apps:rw
      - /volume2/docker/nextcloud/config:/var/www/html/config:rw
      - /volume2/docker/nextcloud/data:/var/www/html/data:rw
      - /volume2/docker/nextcloud/themes:/var/www/html/themes:rw
    image: nextcloud
    restart: on-failure:5
    
  cron:
   image: nextcloud:apache
   container_name: Nextcloud-CRON
   restart: always
   volumes:
     - /volume2/docker/nextcloud/config:/var/www/html/config:rw
     - /volume2/docker/nextcloud/html:/var/www/html:rw
     - /volume2/docker/nextcloud/custom_apps:/var/www/html/custom_apps:rw
     - /volume2/docker/nextcloud/data:/var/www/html/data:rw
   entrypoint: /cron.sh
   depends_on:
    mariadb:
       condition: service_started
    redis:
       condition: service_started

This works as expected and i can use nextcloud via GUI normal.
I copy some of my photo folders into the correspondending data folder of my user, but need to index them.

i cant understand, why this is not possible via GUI but i cant do it via occ.
i google a lot and tried some of the mentioned commands, but nothing worked.

can someone pls help me on how to index all files and folders via a portainer installation on a synology nas.
Best would be a sheduled job to index all files/folders once or twice a day…

my occ is located in var/www/html

root@123456789:/var/www/html# ls -la
total 1248
drwxrwxrwx 1 www-data www-data     582 Oct 17 10:38 .
drwxrwxr-x 1 www-data root          16 Oct 17 06:23 ..
-rwxrwxrwx 1     1026 users       5510 Oct 17 10:37 .htaccess
drwxr-xr-x 1 www-data www-data       8 Oct 17 09:49 .reuse
-rw-r--r-- 1 www-data www-data     271 Oct 17 09:49 .user.ini
drwxr-xr-x 1 www-data www-data     772 Oct 17 09:49 3rdparty
-rw-r--r-- 1 www-data www-data   26314 Oct 17 09:49 AUTHORS
-rw-r--r-- 1 www-data www-data   34520 Oct 17 09:49 COPYING
drwxr-xr-x 1 www-data www-data    1210 Oct 17 09:49 LICENSES
drwxr-xr-x 1 www-data www-data    1316 Oct 17 09:49 apps
-rw-r--r-- 1 www-data www-data    2079 Oct 17 09:49 composer.json
-rw-r--r-- 1 www-data www-data    3400 Oct 17 09:49 composer.lock
drwxrwxrwx 1 www-data www-data     446 Oct 17 09:49 config
-rw-r--r-- 1 www-data www-data    3810 Oct 17 09:49 console.php
drwxr-xr-x 1 www-data www-data     782 Oct 17 09:49 core
-rw-r--r-- 1 www-data www-data    7550 Oct 17 09:49 cron.php
drwxrwxrwx 1 www-data www-data      28 Oct 19 04:41 custom_apps
drwxrwx--- 1 www-data www-data     126 Oct 17 09:52 data
drwxr-xr-x 1 www-data www-data   22292 Oct 17 09:49 dist
-rw-r--r-- 1 www-data www-data     331 Oct 17 09:49 index.html
-rw-r--r-- 1 www-data www-data    3485 Oct 17 09:49 index.php
drwxr-xr-x 1 www-data www-data     126 Oct 17 09:49 lib
-rwxrwxrwx 1 root     root           0 Oct 17 09:55 nextcloud-init-sync.lock
-rwxr-xr-x 1 www-data www-data     308 Oct 17 09:49 occ
drwxr-xr-x 1 www-data www-data      50 Oct 17 09:49 ocs
drwxr-xr-x 1 www-data www-data      18 Oct 17 09:49 ocs-provider
-rw-r--r-- 1 www-data www-data 1131197 Oct 17 09:49 package-lock.json
-rw-r--r-- 1 www-data www-data    7225 Oct 17 09:49 package.json
-rw-r--r-- 1 www-data www-data    2821 Oct 17 09:49 public.php
-rw-r--r-- 1 www-data www-data    4435 Oct 17 09:49 remote.php
drwxr-xr-x 1 www-data www-data     198 Oct 17 09:49 resources
-rw-r--r-- 1 www-data www-data      26 Oct 17 09:49 robots.txt
-rw-r--r-- 1 www-data www-data    1327 Oct 17 09:49 status.php
drwxrwxrwx 1 www-data www-data      26 Oct 17 09:49 themes
-rw-r--r-- 1 www-data www-data     384 Oct 17 09:49 version.php
root@123456789:/var/www/html# 

this is, what i already tried inside portainers docker commandline
(click on the nextcloud container and then >_ Console and connect as root with /bin/bash)

root@123456789:/var/www/html# occ files:scan --all
bash: occ: command not found
root@123456789:/var/www/html# 
root@123456789:/var/www/html# 
root@123456789:/var/www/html# docker compose exec --user www-data app php occ files:scan --all
bash: docker: command not found
root@123456789:/var/www/html# 
root@123456789:/var/www/html# 
root@123456789:/var/www/html# docker exec nextcloud sudo -u www-data php /var/www/html/occ files:scan --all
bash: docker: command not found
root@123456789:/var/www/html# 
root@123456789:/var/www/html# 
root@123456789:/var/www/html# sudo -u www-data php /var/www/html/occ files:scan --all
bash: sudo: command not found
root@123456789:/var/www/html# 
root@123456789:/var/www/html# 
root@123456789:/var/www/html# php occ files:scan --all
Console has to be executed with the user that owns the file config/config.php
Current user id: 0
Owner id of config.php: 33
Try adding 'sudo -u #33' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u 33' to the docker command (without the single quotes)
root@123456789:/var/www/html# 
root@123456789:/var/www/html# 

thank you!

I use Nextcloud AIO and for a similar purpose, I use this command for rescan:

sudo docker exec --user www-data -it nextcloud-aio-nextcloud php occ files:scan-app-data && sudo docker exec --user www-data -it nextcloud-aio-nextcloud php occ files:scan --all

Maybe it helps.

2 Likes

Exec in as www-data or 33.

Use ./occ or /var/www/html/occ or php occ.

https://github.com/nextcloud/docker/?tab=readme-ov-file#using-the-nextcloud-command-line-interface

2 Likes

that do the trick @jtr :grinning:
THANK YOU !!!

www-data@123456789:~/html$ php occ files:scan --all
Starting scan for user 1 out of 1 (MyNCUser)
+---------+-------+-----+---------+---------+--------+--------------+
| Folders | Files | New | Updated | Removed | Errors | Elapsed time |
+---------+-------+-----+---------+---------+--------+--------------+
| 11      | 305   | 0   | 257     | 0       | 0      | 00:00:01     |
+---------+-------+-----+---------+---------+--------+--------------+
www-data@123456789:~/html$ 

is there a way to execute such a command outside the container via synology sheduled task? so that i can do that automatically twice a day?

/edit: got it :grinning: thx @vawaver

on my synology via normal commandline

SampleUser@Synology:~$ sudo docker exec --user www-data -it Nextcloud php occ files:scan --all
Starting scan for user 1 out of 1 (MyNCUser)
+---------+-------+-----+---------+---------+--------+--------------+
| Folders | Files | New | Updated | Removed | Errors | Elapsed time |
+---------+-------+-----+---------+---------+--------+--------------+
| 11      | 305   | 0   | 0       | 0       | 0      | 00:00:00     |
+---------+-------+-----+---------+---------+--------+--------------+
SampleUser@Synology:~$ 

or via sheduled task in Synology GUI without the -it flag
(user must be root)
docker exec --user www-data Nextcloud php occ files:scan --all