Help you to schedule to restart containers at same way as crontab, but inside docker-compose file.
2.9K
This app will help you schedule container restarts in the same way as crontab, but inside the docker-compose file, together your projects.
https://github.com/hudsonventura/Crono
You can inform a time (like crontab) to restart like this:
It uses less than 1 MB of RAM with 4 containers.

A distro Linux, docker, docker-compose, some knowledge about it and Crontab.
version: '3'
services:
service1:
image: "postgres"
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=myStr0ngP4ssw0rd
labels:
crono: "* * * * *"
service2:
image: "postgres"
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=myStr0ngP4ssw0rd
labels:
crono: "@hourly"
service3:
image: "postgres"
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=myStr0ngP4ssw0rd
labels:
crono: "5 0 * 8 *"
service4:
image: "postgres"
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=myStr0ngP4ssw0rd
labels:
crono: "50-59 * * * 1-5"
See that inside each service I put a label called crono. This will call to Crono that we want to restart it (or start if it was down). The value of this will be the same as Crontab.
For help you, you can see crontab.guru at https://crontab.guru
You can infform some keys like @yearly, @annually, @monthly, @weekly, @daily or @hourly.
Functional example 1:
crono:
image: hudsonventura/crono:latest
restart: always
volumes:
- "./docker-compose.yml:/app/docker-compose.yml"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
#- "./logs/:/app/logs/" #Optional
environment:
#- TZ=America/Sao_Paulo
- WAIT=10
The volume - "./docker-compose.yml:/app/docker-compose.yml", you have to point your docker-compose file. Crono will read this file to work.
The volume - "/var/run/docker.sock:/var/run/docker.sock:ro", will used from Crono to call Docker Api.
The volume - "./logs/:/app/logs/", will used to persist logs, if you need.
The environment #- TZ=America/Sao_Paulo, you can identify a timezone. If you ignore, it'll assume Etc/UTC. You can see a complete list in https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
The environment WAIT=10 It'll wait how many seconds you set before read and start the operations on you containers.
Just:
sudo docker compose up
Content type
Image
Digest
sha256:618fd30a7…
Size
7 MB
Last updated
almost 2 years ago
docker pull hudsonventura/crono