Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请改善对非root用户运行docker的支持 #2339

Open
1 task done
JoeyLearnsToCode opened this issue Apr 16, 2024 · 4 comments
Open
1 task done

请改善对非root用户运行docker的支持 #2339

JoeyLearnsToCode opened this issue Apr 16, 2024 · 4 comments

Comments

@JoeyLearnsToCode
Copy link

JoeyLearnsToCode commented Apr 16, 2024

Clear and concise description of the problem

我的环境不能用root用户运行docker,青龙无法直接使用。我有一点编程基础,改了改Dockerfile重新编译,总算能够启动了。
但是启动后添加新定时任务时会报错,刷新一下会发现任务能够被查询出来,但是不会被定时执行。
我查了一下,可能是因为alpine系统上crond、crontab命令要求root权限?

Suggested solution

把对系统crond、crontab的依赖替换为 https://github.com/gjcarneiro/yacron 这种应用级的实现应该能从本质上解决这个问题。
但是这可能不现实,开发量太大。
如果官方能提供“以非root用户运行”的指引文档,相信会对很多人有所帮助。
或者,能否指导下,一次新增定时任务从前端发起请求,到后端经历了哪些步骤? 我猜在我的情况下,报错的是最后一步——把定时任务添加到crontabs中时。但是我看代码绕晕了,不知道这一步是在哪里😭

Alternative

No response

Additional context

https://stackoverflow.com/questions/36453787/failed-to-edit-crontab-linux-alpine
https://gitlab.alpinelinux.org/alpine/aports/-/issues/5380

Validations

  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@JoeyLearnsToCode
Copy link
Author

JoeyLearnsToCode commented Apr 17, 2024

之前苦寻几天都没有进展,昨天提了issue之后却自行找到了方案:
alpine系统中crond和crontab都是对busybox的引用,要让crontab可以被非root用户执行,需要在Dockerfile中以root用户执行这2个命令:chmod 4755 /bin/buxyboxchmod 4755 /usr/bin/crontab
然后,在docker运行时就可以非root用户来运行了(当然,需要用户对Dockerfile做修改(各种文件路径需要修改权限))。
总之,要用非root用户运行青龙并不简单,除非万不得已否则不推荐。

参考:https://unix.stackexchange.com/questions/605653/file-permissions-what-is-the-difference-between-755-and-4755

@whyour
Copy link
Owner

whyour commented Apr 17, 2024

@JoeyLearnsToCode debian 版本会有问题吗

@JoeyLearnsToCode
Copy link
Author

@JoeyLearnsToCode debian 版本会有问题吗

还没试,明天尝试下

@JoeyLearnsToCode
Copy link
Author

@JoeyLearnsToCode debian 版本会有问题吗

debian版本相对alpine版本兼容非 root 用户更简单一些,没有crontab的奇怪问题,只需要在 Dockerfile 里以 root 用户给非root用户赋予一些目录的权限即可。

我是基于debian 分支的 Dockerfile来进行修改的,发现两个问题:

  • 我感觉 debian 分支的 Dockerfile 中 QL_BRANCH 应该是 debian,用 develop 启动会有问题
  • apt install 没有安装 cron,在我的尝试中会导致无法启动,添加后就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants