I succeeded to run my python code in a docker container when using CMD ["python3", "./mycode.py"]
.
Now, what I want is to run that python code every minute.
Dockerfile before(just run once):
FROM python:3.7
RUN apt-get update && \
apt-get install cron -y
RUN pip3 install requests
RUN head -n -1 /etc/ssl/openssl.cnf > /etc/ssl/temp && \
mv /etc/ssl/temp /etc/ssl/openssl.cnf
RUN echo "CipherString=DEFAULT@SECLEVEL=1" >> /etc/ssl/openssl.cnf
COPY . /app
WORKDIR /app
CMD ["python3", "./mycode.py"]
Dockerfile after(run every minute with crontab):
FROM python:3.7
RUN apt-get update && \
apt-get install cron -y
RUN pip3 install requests
RUN head -n -1 /etc/ssl/openssl.cnf > /etc/ssl/temp && \
mv /etc/ssl/temp /etc/ssl/openssl.cnf
RUN echo "CipherString=DEFAULT@SECLEVEL=1" >> /etc/ssl/openssl.cnf
RUN echo "* * * * * python /app/mycode.py" >> editcron && \
crontab editcron
COPY . /app
WORKDIR /app
CMD ["cron", "-f"]
But after building and running a new docker image with docker run -d --rm DockerImage
, it doesn't seem to work.(And also, there is no cron log file at /var/log directory)
When I went into the container with docker exec -it DockerContainer /bin/bash
, I could confirm that crontab -l
prints "* * * * * python /app/mycode.py", and that python /app/mycode.py
runs properly.
What could be a problem here?