Issues running cron in Docker on different hosts

前端 未结 4 1221
谎友^
谎友^ 2020-12-15 03:56

Im trying to get a docker container running to mange my cronjobs

im running a very simple cron as a test in a docker container using centOS 6.5 base



        
相关标签:
4条回答
  • 2020-12-15 04:27

    @dwitz's answer is correct but I had to alter the sed command a bit to make it work for me on Ubuntu 16.04 within a docker container.

    cat /etc/pam.d/cron |sed -e "s/required     pam_loginuid.so/optional     pam_loginuid.so/g" > /tmp/cron && mv /tmp/cron /etc/pam.d/cron 
    
    0 讨论(0)
  • 2020-12-15 04:31

    the base Docker containers don't start services like cron - they only start what you specify in the ENTRYPOINT/CMD

    some 'fatter' containers use things like supervisord to start services - but where possible, its more maintainable to separate services into different containers and share data using with volume containers, or --link

    0 讨论(0)
  • 2020-12-15 04:47

    In my case, I debug the cron:

    $ apt-get install rsyslog
    $ rsyslogd
    $ service cron restart
    $ tail -f /var/log/syslog
    

    And found NUMBER OF HARD LINKS > 1 error in logs.

    The solution was to put this in entrypoint.sh

    touch /etc/crontab /etc/cron.d/*
    

    and boom!

    0 讨论(0)
  • 2020-12-15 04:49

    short answer

    add this line to your dockerfile

    RUN sed -i '/session    required   pam_loginuid.so/c\#session    required   pam_loginuid.so' /etc/pam.d/crond
    

    the long answer

    from what I understand issue is related to differences in the kernal between CoreOS & Unbutu. this in-turn causes a pam security issue.

    to figure it our first needed to turn on logging for cron (since we are in docker normal startup is not executed). run

    service rsyslog start
    service crond restart
    

    the cron log had this error (located here /var/log/cron)

    FAILED to open PAM security session (Cannot make/remove an entry for the specified session)
    

    so then I took a look at the security log, and it had this error (located here /var/log/secure)

    pam_loginuid(crond:session): set_loginuid failed
    

    some more googling and found I needed to modify my pam cond config (found here /etc/pam.d/crond) edit this file and comment out the following line

    #session    required   pam_loginuid.so
    

    restart crond and all should be good

    0 讨论(0)
提交回复
热议问题