当我尝试使用 docker 运行 owncloud 时,一切都很好。但是当我尝试以其他用户身份运行它时,我总是收到以下错误:
docker run --user 1005:1005 owncloud/server:latest
/etc/entrypoint.d/05-nsswrapper.sh:第 8 行:/home/owncloud/passwd:权限被拒绝
如果没有
--user 1005:1005
选项,容器将正常启动。
我想做的最初的事情是使用 docker compose 运行 owncloud 并以其他用户身份运行它,这样我就可以在另一个磁盘上拥有一个包含数据的卷,因为带有操作系统的默认磁盘没有足够的空间。我已经将所有权更改为名为
owncloud
的用户,并使用 uid=gid=1005
我还查看了 docker 镜像的文档以及 https://hub.docker.com/_/php/ 部分
Running as an arbitrary user
。但这对我不起作用。当查看 docker 镜像内部时,有一个名为 /home/owncloud
的文件夹,其所有权为 root
。我已经在与专门用户一起运行其他服务并且没有遇到此类问题。
我看到了同样的错误。因此,我创建了以下
Dockerfile
,它继承自 owncloud/server:10.13.1-amd64
。
FROM owncloud/server:10.13.1-amd64
# user and group IDs used to run the Docker process.
ARG SERVICE_USER=owncloud_server
ENV SERVICE_USER=${SERVICE_USER:-owncloud_server}
ARG SERVICE_GROUP=root
ENV SERVICE_GROUP=${SERVICE_GROUP:-root}
ARG SERVICE_USER_ID=534
ENV SERVICE_USER_ID=${SERVICE_USER_ID:-534}
ARG SERVICE_GROUP_ID=0
ENV SERVICE_GROUP_ID=${SERVICE_GROUP_ID:-0}
#RUN groupadd --gid ${SERVICE_GROUP_ID} ${SERVICE_GROUP}
RUN useradd --uid ${SERVICE_USER_ID} \
--gid ${SERVICE_GROUP_ID} \
--home-dir /home/${SERVICE_USER} \
--create-home \
${SERVICE_USER}
# change ownership of Own Cloud files and directories
RUN chown -R ${SERVICE_USER}:${SERVICE_GROUP} \
/etc/cron.d \
/var/www/html \
/var/www/.cache \
/var/log/apache2 \
/var/run/apache2 \
/var/www/owncloud \
/mnt/data
USER ${SERVICE_USER}
效果好多了,但是还是启动失败,输出最后还是出现如下错误:
php_1 | services are ready!
php_1 | Waiting for Redis...
php_1 | services are ready!
php_1 | Removing custom folder...
php_1 | Linking custom folder...
php_1 | Removing config folder...
php_1 | Linking config folder...
php_1 | Writing config file...
php_1 | Skipping chown as requested...
php_1 | Skipping chmod as requested...
php_1 | Installing server database...
php_1 | ownCloud was successfully installed
php_1 | ownCloud is already latest version
php_1 | Writing objectstore config...
php_1 | Writing php config...
php_1 | Updating htaccess config...
php_1 | .htaccess has been updated
php_1 | Writing apache config...
php_1 | Enabling cron background...
php_1 | Set mode for background jobs to 'cron'
php_1 | Writing crontab file...
php_1 | Touching cron configs...
php_1 | Starting cron daemon...
php_1 | seteuid: Operation not permitted
我可以在系统启动时执行的
overlay/etc/owncloud.d/25-chown.sh
中看到,一堆目录的权限被修改。然而,该脚本似乎执行时没有错误。我看到的错误,seteuid: Operation not permitted
,似乎是由其他一些代码或脚本生成的,不确定是哪个。