Do not run crontab from docker container

0

I'm trying to set up a crontab from docker, the code I have is like this:

 # Web container
FROM debian:jessie

RUN apt-get update
RUN apt-get install -y cron curl apt-utils nano curl apache2 apache2-utils libmysqlclient-dev
RUN apt-get -y install python3 libapache2-mod-wsgi-py3 gettext
RUN ln /usr/bin/python3 /usr/bin/python
RUN apt-get -y install python3-pip
RUN ln /usr/bin/pip3 /usr/bin/pip
RUN pip install --upgrade pip

ADD ./webapp_2.conf /etc/apache2/sites-available/000-default_000.conf
RUN mkdir /webapp
WORKDIR /webapp
ADD ./requirements.txt /webapp/ 
RUN pip install -r requirements.txt
ADD . /webapp/

ADD ./crontab /var/spool/cron/crontabs/root
RUN chmod 0600 /var/spool/cron/crontabs/root

CMD touch /var/log/cron.log && cron && env > /root/env.sh && tail -f /var/log/cron.log

CMD ["/usr/sbin/crond", "-f", "-d", "0"]
CMD ["/usr/sbin/apache2", "-D",  "FOREGROUND"]

But until the mento no logo execute the process, can someone please help me or tell me what I'm missing?

Thank you very much.

    
asked by Inés Peña 13.12.2018 в 02:44
source

1 answer

0

CMD can only be used once (only the last one has an effect). It is not used to execute commands, but to specify which command will be executed when you instantiate the container without passing as an argument what command to execute.

In your case, if you create the image by giving it a name such as miprueba :

$ docker build -t miprueba .

And then the instances without specifying command:

$ docker run miprueba

the command specified in the last CMD of the dockerfile will be executed, ignoring the previous ones.

The solution when you want to execute several commands is to write them all in a shell scrip and use as CMD of the Dockerfile one that launches a shell (eg, bash) passing it as a parameter that script. Another option is to use the syntax "shell" for CMD , and thus use operators such as && to throw several on a line.

    
answered by 13.12.2018 в 18:06