cron服务未启动post-doker运行,容器正在退出



尝试通过dockerfile运行cron,但在运行容器时,它会退出。下面是我的摘要文件和错误。如有任何帮助,将不胜感激

错误:

docker:来自守护进程的错误响应:OCI运行时创建失败:container_linux.go:380:启动容器进程导致:exec:"cron":在$PATH中找不到可执行文件:未知。

Dockerfile:

# Pull base image.
FROM amazonlinux:2
ARG TERRAFORM_VERSION=1.2.6
RUN 
yum update -y && 
yum install unzip -y && 
yum install wget -y && 
yum install vim -y 
yum install bash -y
################################
# Install Terraform
################################
# Download terraform for linux
RUN wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
RUN unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip
RUN mv terraform /usr/local/bin/

################################
# Install python
################################
RUN yum install -y python3-pip
RUN pip3 install --upgrade pip

################################
# Install AWS CLI
################################
RUN pip install awscli --upgrade --user
# add aws cli location to path
ENV PATH=~/.local/bin:$PATH

RUN mkdir ~/.aws && touch ~/.aws/credentials

################################
# Install Cron
################################
RUN yum -y install ca-certificates shadow-utils cronie && yum -y clean all
# Creating crontab
COPY  ./automation.sh /var/automation.sh

# Giving executable permission to script file.
RUN chmod +x /var/automation.sh 
&& echo "* * * * *  /bin/bash /var/automation.sh" >> /var/crontab

# Ensure sudo group users are not asked for a password
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> 
/etc/sudoers
#run cron process through cmd
CMD ["cron", "-f"]

任何想找到答案的人,我都不得不改变运行cron的方法,它终于奏效了。这是更新方法的dockerfile。

# Pull base image.
FROM amazonlinux:2
ARG TERRAFORM_VERSION=1.2.6
################################
# Install Dependencies
################################
RUN yum update -y && yum -y install unzip wget vim bash procps python3-pip jq git && pip3 install --upgrade pip
################################
# Install AWS CLI
################################
RUN pip install awscli --upgrade --user
# add aws cli location to path
ENV PATH=~/.local/bin:$PATH
RUN mkdir ~/.aws && touch ~/.aws/credentials
################################
# Install Terraform
################################
# Download terraform for linux
RUN wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip
RUN unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip
RUN mv terraform /usr/local/bin/
################################
# Install Cron
################################
RUN yum -y install ca-certificates shadow-utils cronie && yum -y clean all
# Creating crontab
COPY  ./automation.sh /var/automation.sh

# Giving executable permission to script file.
RUN chmod +x /var/automation.sh 
&& echo "* * * * *  /bin/bash /var/automation.sh" >> /var/crontab
RUN crontab /var/crontab
# Ensure sudo group users are not asked for a password
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> 
/etc/sudoers
#run cron process through cmd
CMD ["/usr/sbin/crond", "-n"]

将CMD更新为:

CMD ["/usr/bin/crontab", "/var/crontab"]

最新更新