docker -u 容器内部没有sudo的处理方案。docker容器化的nextcloud忘记密码的处理。

发布时间 2023-07-16 06:37:09作者: 上官飞鸿

简介:

今天在调试nextclou和AD域控互联。结果脑子抽了,刚安装完的nextcloud,居然忘记了管理用户密码。

虽然重新启一下docker挺方便,但是为了以后更好的使用运维nextcloud,还是另找一下解决方案吧。

一:解决方案occ

sudo -u http php occ user:resetpassword 用户名
sudo -u http php occ user:list
 user
  user:add                            添加一个用户
  user:delete                         删除特定用户
  user:disable                        禁用特定用户
  user:enable                         激活特定用户
  user:info                           显示用户信息
  user:lastseen                       显示用户最后登陆了时间
  user:list                           列出所有用户
  user:report                         显示有多少用户访问
  user:resetpassword                  为一个用户重置密码
  user:setting                        读取和修改用户设置

二:容器操作

找到occ,执行occ

# cd /
# find -name occ
……
./usr/src/nextcloud/occ
./var/www/html/occ
# cd /var/www/html
# cat occ
#!/usr/bin/env php
<?php
……
require_once __DIR__ . '/console.php';
# ls -la occ
-rwxr-xr-x. 1 www-data www-data 283 Jul 15 02:31 occ
# php occ user:list
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)
#  with 'docker exec' try adding the option '-u 33' to the docker command (without the single quotes)
sh: 22: Syntax error: "(" unexpected
# exit

毫不意外的出错了,容器没有sudo,但是提示我使用 -u 33 加入docker命令。

[root@design ~]# docker exec -it -u 33  nextcloud-app-1 sh
$ ls
3rdparty     core         index.php                 ocs-provider  themes
AUTHORS      cron.php     lib                       public.php    version.php
COPYING      custom_apps  nextcloud-init-sync.lock  remote.php
apps         data         occ                       resources
config       dist         ocm-provider              robots.txt
console.php  index.html   ocs                       status.php
$ php occ user:list
  - jack: jack

使用 -u 33 进入容器

使用 php occ 命令即可。

以后使用nextcloud,就可以使用occ命令了。

升级nextcloud,也是需要使用occ命令进行数据扫描,数据库重建的。