Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues running cron in Docker on different hosts

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

* * * * * /bin/echo "it works!" >> test.log 

it works fine if the container is running on CoreOS host, however if I run the container on a ubuntu 13.10 host the cron is not executed. (I though the host did not effect what was running in the container)

both hosts are running docker 0.8

am I missing something obvious, or it this a bug?

thanks

like image 861
dwitz Avatar asked Feb 21 '14 06:02

dwitz


People also ask

Can Docker run on multiple machines?

Docker defines an abstraction for these machine-specific settings. The exact same Docker container can run - unchanged - on many different machines, with many different configurations. Application-centric. Docker is optimized for the deployment of applications, as opposed to machines.

Can Docker container talk to each other?

If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network. Docker creates virtual networks which let your containers talk to each other. In a network, a container has an IP address, and optionally a hostname.

Can we run multiple apps on one server with Docker?

It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.


1 Answers

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

like image 128
dwitz Avatar answered Sep 21 '22 08:09

dwitz