implement docker cron job

This commit is contained in:
2024-12-04 13:26:13 -06:00
parent b75d8e06f2
commit 1f6247d3d3
6 changed files with 105 additions and 0 deletions

39
Dockerfile Normal file
View File

@@ -0,0 +1,39 @@
# Use Ubuntu 20.04 as the base image
FROM ubuntu:20.04
# Install dependencies
RUN apt-get update && apt-get install -y \
sqlite3 \
awscli \
cron \
tar \
gzip \
&& rm -rf /var/lib/apt/lists/*
# Create necessary directories
RUN mkdir -p /jobs/data/sqlite
RUN mkdir -p /var/tmp
# Copy the backup script into the container
COPY backup_sqlite.sh /usr/local/bin/backup_script.sh
# Make the script executable
RUN chmod +x /usr/local/bin/backup_script.sh
# Create the cron log file
RUN touch /var/log/cron.log
# Copy the cron job file into the cron.d directory
COPY backup_cron /etc/cron.d/backup_cron
# Set permissions for the cron job file
RUN chmod 0644 /etc/cron.d/backup_cron
# Apply the cron job
RUN crontab /etc/cron.d/backup_cron
# Expose the cron log file as a volume
VOLUME /var/log
# Start cron in the foreground when the container starts
CMD ["cron", "-f"]