Reset admin password in docker

  • Nextcloud Server version (e.g., 29.x.x):
    • latest
  • Operating system and version (e.g., Ubuntu 24.04):
    • Alpine Linux 3.21.3
  • Web server and version (e.g, Apache 2.4.25):
    • maybe Appache2 (default install and last version on docker)
  • Is this the first time you’ve seen this error? (Yes / No):
    • yes
  • When did this problem seem to first start?
    • after install
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • docker
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • no

Summary of the issue you are facing:

I installed Nextcloud on docker yesterday and I forgot to save it in my KeePass.

I saw that on the documentation you had to use this command:
sudo -u www-data php /var/www/nextcloud/occ user:resetpassword admin

But in the container, there is no sudo, and it is not possible to install it.
sudo -u corresponds to su, but su is not allowed.
In addition, the path in my container seems different. I have this location :
/var/www/html/
I also tried this command (my container name is “nextcloud”) :
docker exec nextcloud sudo -u www-data php /var/www/nextcloud/occ user:reset password admin
But return :
OCI runtime exec failed: exec failed: unable to start container process: exec: "sudo": executable file not found in $PATH: unknown

In addition, in my container, if I exec /var/www/html# ./occ user:resetpassword admin, bash say I need to run sudo -u or docker exec

Hi @Arnaud_Skrzek

Have you also tried this… https://github.com/nextcloud/docker#accessing-the-nextcloud-command-line-interface-occ

1 Like

Partialy working :

~% docker exec --user www-data CONTAINER_ID php occ                                                  
Error response from daemon: No such container: CONTAINER_ID

I imagine CONTAINER_ID is my container id or name :


~% docker exec --user www-data nextcloud php occ user:resetpassword admin
Enter a new password: 
            
  Aborted.  
            

user:resetpassword [--password-from-env] [--] <user>

It won’t let me enter the password. It aborts immediately.

If I add --password-from-env before username :
--password-from-env given, but OC_PASS is empty!

Oops, there is a typo in the non-compose version of the command there (at least if you want to use it for an interactive session). I’ll fix that now. Add --it if not using the Compose variant:

docker exec -it --user www-data CONTAINER_ID php occ

EDIT: Fixed in the README.

2 Likes

Ho good ! It works.
Finaly for reset admin password in command line, we need use :
docker exec -it --user www-data CONTAINER_ID php occ user:resetpassword admin

And this command can be used for other user.

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.