3

I am trying to run cron job on Docker container. I have a running container (Fedora 20). I have also installed cron packages in container and explicitly run the cron daemon. I have also checked cron.deny file it is empty and there is no file called cron.allow under /etc/ directory.

Whenever I tried to set the cronjob by using crontab -e or trying to list the cron job using 

    crontab -l I am getting following error.

bash-4.2# crontab -l
You (root) are not allowed to access to (crontab) because of pam configuration.


bash-4.2# crontab -e
You (root) are not allowed to access to (crontab) because of pam configuration.

I also checked the /etc/pam.d/crond file it has following entry

bash-4.2# vi /etc/pam.d/crond

#
# The PAM configuration file for the cron daemon
#
#
# No PAM authentication called, auth modules not needed

account    required   pam_access.so
account    include    password-auth
session    required   pam_loginuid.so
session    include    password-auth
auth       include    password-auth

Has any one faced this issue? If yes could you please suggest me some pointer on this?

thanks in advance.

rgaut
  • 3,159
  • 5
  • 25
  • 29

2 Answers2

8

An LXC container is not a virtual machine. You'll need to explictly run the cron daemon in the foreground. Better still run cron from program like Supervisor or runit.

Reference: Docker documentation

Traditionally a Docker container runs a single process when it is launched, for example an Apache daemon or a SSH server daemon. Often though you want to run more than one process in a container. There are a number of ways you can achieve this ranging from using a simple Bash script as the value of your container's CMD instruction to installing a process management tool.

In this example we're going to make use of the process management tool, Supervisor, to manage multiple processes in our container. Using Supervisor allows us to better control, manage, and restart the processes we want to run. To demonstrate this we're going to install and manage both an SSH daemon and an Apache daemon.

ericteubert
  • 4,531
  • 3
  • 31
  • 35
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • thank you Mark for your reply. Will running the cron daemon in background not work? If I need to run as a FOREGROUND then do I need to use multiple screen or probably attaching the container from other terminal. – rgaut Jul 25 '14 at 13:34
  • @GautamGoswami I have expanded my answer. An LXC container generally runs a single process, to run more you need some form of process management. A container doesn't perform traditional OS activities such as bootstrapping background services. It is not a virtual machine. – Mark O'Connor Jul 25 '14 at 18:34
  • Hi Mark, I have a silly doubt, I am already running apache and mysql daemon in background and its working fine. In the same way why can't I run the cron daemon? thanks in advance. – rgaut Jul 29 '14 at 19:18
  • 1
    @GautamGoswami http://stackoverflow.com/questions/20545554/how-do-i-start-cron-on-docker-ubuntu-base or http://programster.blogspot.ie/2014/01/docker-working-with-cronjobs.html – Mark O'Connor Jul 29 '14 at 19:22
3

You can do:

ENTRYPOINT cron -f

although remember that you can only have one ENTRYPOINT.

From the docs:

There can only be one ENTRYPOINT in a Dockerfile. If you have more than one ENTRYPOINT, then only the last one in the Dockerfile will have an effect.

An ENTRYPOINT helps you to configure a container that you can run as an executable. That is, when you specify an ENTRYPOINT, then the whole container runs as if it was just that executable.

Col Wilson
  • 889
  • 10
  • 16