大网数据广告活动
服务器运维问答

docker - no crontab for root

· 52CE 我爱测

My Dockerfile appears to build correctly (it tells me so). When I run the container, I get the below error message. I have tried running the commands ( CMD ) with and without the service's directory. crontab.sh basically writes a…

问题原文

原帖链接 · TomFirth · CC BY-SA 3.0

My Dockerfile appears to build correctly (it tells me so). When I run the container, I get the below error message. I have tried running the commands (CMD) with and without the service's directory.

crontab.sh basically writes a cron schedule to a text file (cron.jobs) and then imports the text file to crontab.

Dockerfile:

FROM node:0.10
MAINTAINER Tom

VOLUME /var/log/

RUN mkdir /pulse
ADD . /pulse
WORKDIR /pulse

RUN apt-get update && apt-get install -y cron

ADD *.sh /pulse/
RUN chmod 750 /pulse/crontab.sh && chmod 750 /pulse/

RUN chmod 644 /etc/crontab

CMD cron -f
CMD touch /var/log/cron.log && sh /pulse/crontab.sh && tail -f /var/log/cron.log
CMD cron /pulse/cron.jobs
CMD crontab -l

edited to add crontab.sh

crontab.sh (some crons have been removed):

#!/bin/bash

cat <<- 'EOF' > cron.jobs

0 * * * * node /pulse/scripts/awsPulseTest.js > /tmp/awsPulseTest.log 2>&1

EOF

crontab cron.jobs

Error:

no crontab for root

Side notes:

  • Pulse is the name of the service.
  • The version of node is old due to the service, this will be upgraded.
  • The service is essentially for cron jobs in node

已采纳解答

原帖链接 · Paul Haldane · CC BY-SA 3.0

It's an issue with the dockerfile (rather than the commands in the file). Only one CMD is run (the last one) - see https://docs.docker.com/engine/reference/builder/#cmd

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。