Skip to content

Instantly share code, notes, and snippets.

@zenthangplus zenthangplus/Dockerfile
Last active Apr 3, 2019

Embed
What would you like to do?
Redirect logs from file to docker's output
# To do that, you need to create symlink from your file (inside container) to docker's output file.
# Add bellow line to your Dockerfile
RUN ln -sf /proc/1/fd/1 /var/log/cronjob.log
# EXPLAIN:
# The first 1 is the PID of docker process.
# The second 1 is standard output
# Note: If you launch your container with --pid=host, please use following line
RUN ln -sf /proc/$$/fd/1 /var/log/cronjob.log
# EXPLAIN:
# $$ is the PID of the current script itself.
FROM php:7.2-fpm
RUN apt-get update && apt-get -y install cron
# Create crontab file in the cron directory
RUN echo "* * * * * /usr/local/bin/php -r \"echo time() . PHP_EOL;\" >> /var/log/cronjob.log 2>&1" > /etc/cron.d/crontab
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/crontab
# Apply cron job
RUN crontab /etc/cron.d/crontab
# Create cronjob log file
RUN touch /var/log/cronjob.log
# Redirect cronjob log to docker log collector
RUN ln -sf /proc/$$/fd/1 /var/log/cronjob.log
CMD ["bash", "-c", "cron -f & php-fpm"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.