I followed the suggested solution for this question. And came up with the following docker file
FROM ubuntu:16.04
ADD write_time.py /
USER root
RUN apt-get update && \
apt-get install -y python cron && \
chmod +x /write_time.py && \
(crontab -l 2>/dev/null; echo "* * * * * cd / && /usr/bin/python /write_time.py >> test.out") | crontab -
the write_time.py is
#!/usr/bin/env python
import datetime
time = datetime.datetime.now()
time = time.strftime("%Y-%m-%dT%H:%M:%S.%f")
print(time)
with open("time.txt", "a") as f:
f.write(time+"\n")
After i build with the below command and run it -
docker build . -t se
docker run -it se
I exec into the contaier, to check if either test.out or test.txt is created at / but i do not see either.(have waited for more than 2 mins)
Anything i am doing wrong here?
Thanks!