0

I am trying run a docker container with python code and crontab (scheduler) below is my script:

Docker file

FROM ubuntu:latest
MAINTAINER [email protected]
RUN apt-get update && apt-get install -y software-properties-common && apt-get install -y python cron vim

# Copy hello-cron file to the cron.d directory
COPY my-crontab /etc/cron.d/my-crontab

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/my-crontab

ADD config.py /
ADD index.py /

RUN chmod a+x config.py index.py
# Apply cron job
RUN crontab /etc/cron.d/my-crontab

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
#CMD cron && tail -f /var/log/cron.log
CMD ["cron", "-f"]

My crontab

*/2 * * * * /index.py > /dev/console

When I create the docker file and run the code its not responding with anything. Please can someone suggest how to modify the docker file to run the script?

0

1 Answer 1

0

You can try entering the container using 'docker container exec -it 'container-id' bash' and from there try to execute the python script, this way checking whether it works or not at all.

From there on there are multiple scenarios, it depends what type of shebang you've entered in the script (e.g. '#!/usr/bin/env python', '#!/usr/bin/python', etc.), which version of python is installed in the container and for which version the script has been written for etc. Without further info can't be of more assistance.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.