简体   繁体   English

在Docker容器中的cron中执行服务时出现问题?

[英]Problems when executing services within cron in a Docker container?

I have some cronjobs that I always used and worked fine. 我有一些我经常使用的cronjobs,并且工作正常。 But now, trying to move everything to Docker containers, I'm running into these errors: 但是现在,尝试将所有内容移至Docker容器,我Docker了以下错误:

/usr/bin/service: 127: /usr/bin/service: stop: not found
/usr/bin/service: 128: exec: start: not found

They occur when executing things like "service restart nginx" these cronjobs. 当执行这些cronjobs之类的"service restart nginx"类的事情时,它们就会发生。 Note that the same commands work fine outside the cronjobs. 注意,相同的命令在cronjobs外部也可以正常工作。

The PATH is correctly set in /etc/crontab . /etc/crontab正确设置了PATH。 Adding it to the individual cronfiles in /etc/cron.d doesn't work either. 将其添加到/etc/cron.d中的单个cronfiles也不起作用。 I also tried changing SHELL=/bin/sh to SHELL=/bin/bash (even though it's insecure, but wanted to try) in /etc/crontab , didn't work. 我还尝试在/etc/crontab中将SHELL=/bin/sh更改为SHELL=/bin/bash (尽管不安全,但想尝试),但没有用。

Any ideas? 有任何想法吗?

I solved it changing the command from 我解决了更改命令从

"service start mysql"

to

"/sbin/start mysql &"

Good luck 祝好运

Enric 安瑞科

I am not sure, but I think that the problem is in paths. 我不确定,但我认为问题出在道路上。 I believe you want to run /usr/sbin/service and not /usr/bin/service . 我相信您想运行/usr/sbin/service而不是/usr/bin/service You may try to specify full path for service instead of just service . 您可以尝试指定服务的完整路径,而不仅仅是service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM