How to use occ comand to add user in docker version?

Nextcloud version (eg, 20.0.5): 24.02
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): apache2
PHP version (eg, 7.4): php 8.0.20

The issue you are facing:

I run a nextcloud with docker-compose. and I could run this command in nextcloud container

www-data@ad41920cfec1:~/html$ OC_PASS="somewhereOVERTHERAINBOW" ./occ user:add --password-from-env --display-name "CH" --group regular changch
The user "changch" was created successfully
Display name set to "CH"
User "changch" added to group "regular"

but outside the container , can’t pass the OC_PASS variable to occ

chchang@dc039:~/docker/nextcloud-libreoffice-online/nextcloud/nextcloud$ docker exec -u 33 -it nextcloud-app-1 OC_PASS="somewhereOVERTHERAINBOW" ./occ user:add --password-from-env --display-name "CH" --group regular changch
OCI runtime exec failed: exec failed: unable to start container process: exec: "OC_PASS=somewhereOVERTHERAINBOW": executable file not found in $PATH: unknown

so I’m wondering if there is any way to add a nextcloud user in docker version with occ command ?? or maybe any other commands to do so ?

do a

root@ucs:/# docker ps|awk '{print $1" "$2}'

in the first column you will get the container-id-
Now login into your docker Nextcloud instance (in ths case the upper line):

root@ucs:/# docker exec -it 3fb2946bb353 /bin/bash

Now you can handle your occ command f.ex. from /var/www/html/ using your OC_PASS variable.

I know that, but I want to add nextcloud “outside” of the container. not running occ in the container.

I find the way to solve it!!

chchang@dc039:~$ docker exec -u www-data -it nextcloud-app-1  sh -c 'export OC_PASS="1qaz@WERTGD#$%" && /var/www/html/occ user:add --password-from-env --display-name CH -g regular changch'
The user "changch" was created successfully
Display name set to "CH"
User "changch" added to group "regular"