tried running cron through dockerfile but when running the container its getting exit. Below is my dockerfile and error. Any help would be really appreciated
Error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "cron": executable file not found in $PATH: unknown.
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"]
2
Answers
Anyone looking for answer to this, I had to change the approach a bit of running cron and it worked finally. Here is the dockerfile with updated approach.
Update the CMD to this: