0

I´m new on docker but i know that a docker container should have only one process. But is it possible to run a script inside of a docker container multiple times like by a cronjob? For example I have a python script which manipulate my database. This process should be done every hour. For that i have created a container based on a file like that:

FROM python:slim
COPY ac.py ac.py
RUN pip install pymongo
CMD [ "python", "./ac.py" ]

If i load this container from my repository and start it on any environment the process is done only one time. Is there any posibillity to start that like a cronjob (without use ubuntu image inside of my docker container)?

By the way I want to deploy this container in google cloud. Is there any cloud provider who provide a functionality like that?

Nico Schuck
  • 832
  • 3
  • 15
  • 32

1 Answers1

0

You could leverage docker swam and create a service that will have restart condition set to any and a delay between restarts set to 1h.

docker service create --restart-condition any --restart-delay 1h myPythonImage:latest

See docker service create reference: https://docs.docker.com/engine/reference/commandline/service_create/#options

Miq
  • 3,931
  • 2
  • 18
  • 32
  • is that doing the restart every hour or only one time after one hour? – Nico Schuck Jun 04 '18 at 09:07
  • it will run a new container based on the image after 1h delay from detecting previous service container is not running (detection is usually in couple seconds). – Miq Jun 04 '18 at 09:10