Giter Club home page Giter Club logo

docker-cron's Introduction

docker-cron

An example of running cron job in a docker container

docker-cron's People

Contributors

thepont avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-cron's Issues

Doesn't work in Docker for Windows

I cloned this repo on my Mac and it worked great. But when I tried it on my Windows 10 laptop running Docker and configured to use Linux containers, nothing ever showed up in /var/log/cron.log.

I'll continue to troubleshoot and update this issue with anything I learn.

cron not started

I am doing exactly like in the example (but using debian:buster-slim instead of ubuntu:latest), but I run an additional command after cron

CMD ["cron"; "postgres", "-c", "hba_file=/etc/pg_hba.conf"]

The second command is started but not cron.

while this is fine but the environment variable declated in the docker file will not be picked up by cron

I disovered even if you have environement variable defined in the dockerfile or in the docker stack file , the environment variable will be available to shell if container but not to the cron. for that you would need to define env variable inside the cron file.

MYSQL_PASSWORD=secret_password
PYTHONPATH=/usr/local/app

*/45 * * * * python3 app.py >> /var/log/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.

Another approach that might be more portable

Thanks for posting this, it got me started. I found an approach (using crontab - < /path/to/crontab) that worked better for me. Thought I would post it here in case others found it useful.

modified   Dockerfile
@@ -1,19 +1,16 @@
 FROM ubuntu:latest
 MAINTAINER [email protected]
 
-# Add crontab file in the cron directory
-ADD crontab /etc/cron.d/hello-cron
-
-# Give execution rights on the cron job
-RUN chmod 0644 /etc/cron.d/hello-cron
-
 # Create the log file to be able to run tail
 RUN touch /var/log/cron.log
 
 #Install Cron
 RUN apt-get update
 RUN apt-get -y install cron
 
+# Install the crontab
+ADD crontab /tmp/crontab
+RUN crontab /tmp/crontab && rm /tmp/crontab
 
 # Run the command on container startup
 CMD cron && tail -f /var/log/cron.log
modified   crontab
@@ -1,2 +1,2 @@
-* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
+* * * * * echo "Hello world" >> /var/log/cron.log 2>&1
 # Don't remove the empty line at the end of this file. It is required to run the cron job

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.