I have got a NAS running from 6am to 12pm. My services are running as docker container using portainer. I have got one special container, that has to check, if my ssl certifcates have to be renewed. After the checkup the container will exit.
If I use in my portainer stack (like docker compose) the restart-policy “always” or “unless-stopped”, the container will asap be restartet, when the checkup finished and stopped the container.
This is not the behavior I want. It is enough, when only one time a day the checkup will be performed. It is best if Portainer is started up in the morning with all containers.
Can I use another option to realize this behavior?
Unfortunately no such restart-policy exists yet. You can raise a feature request in the Moby Github project and ask the implementation of such feature:
Until then, you could use your nas’es scheduling mechanism to start a one-off container every time the nas is restarted, with something like docker run -d --rm ..... The --rm argument will ensure the container is removed after it exits, so that the next scheduling run will not clash with an existing container, or leave orphaned stopped containers .
Not really the solution you are looking for, but you could extend the image, and install GitHub - aptible/supercronic: Cron for containers in your Dockerfile, and make it call the original command at a specific time.
Hi @meyay,
thanks for response. I think in that case I will simply create a cron-job at my host, that will start the container to a defined time. Sadly the portainer “edge job” wont run. That was my second try.