Skip to content

Instantly share code, notes, and snippets.

@li0nel
Last active January 30, 2024 19:09
Show Gist options
  • Save li0nel/f6916b55816d3849641166170e8e8a76 to your computer and use it in GitHub Desktop.
Save li0nel/f6916b55816d3849641166170e8e8a76 to your computer and use it in GitHub Desktop.
Run crons in Docker ; get cron logs as std Docker log
FROM ubuntu:14.04
MAINTAINER li0nel
USER root
# Install CRON
RUN apt-get update && apt-get -y install sudo && \
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 && \
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list && \
apt-get update && \
apt-get install -y mongodb-org cron curl && \
apt-get clean && rm -rf /var/lib/apt/lists/*
RUN mkdir /home/mongobk
RUN echo "mongodump --host 10.0.0.6:27017 --db delta --out /home/mongobk \
&& tar -zcvf - /home/mongobk/delta | curl -X PUT --data-binary @- -H 'x-ms-blob-type: BlockBlob' https://dbbackupxxxxx.blob.core.windows.net/mongo/\$(date +%Y%m%d_%H%M%S).json.gz \
&& rm -rf /home/mongobk/delta" > /home/backup.sh
RUN chmod +x /home/backup.sh
RUN echo "0 * * * * root /home/backup.sh >> /var/log/cron.log 2>&1" > /etc/cron.d/backup
RUN chmod +x /etc/cron.d/backup
RUN touch /var/log/cron.log
CMD cron && tail -f /var/log/cron.log
@hoshang82
Copy link

thank you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment