Search code examples
dockerkubernetesdocker-composedockerfile

Docker - start a container at random time


I have 3 vps with docker installed. I have created a docker image and I would like to know if there is a possibility to configure docker or docker-compose in such a way that these 3 containers run only once a day at random hours.

I have not found any way other than to configure the command to start the docker in a bash script, called from the Linux crontab, which waits for a while at random. Are there better better solutions? Maybe k8s / k3s?


Solution

  • If "randomness" is part of your application behaviour, then you should contain this logic inside one of services / containers, so this is no-brainer. You are running entire stack with docker-compose and it just works.

    Other than that Crontab or other external scheduler (like kubernetes cron jobs) is the way of doing that if running those three containers on random time once a day is your requirement of using those docker services.