0

I'm running a small backend with two docker containers in Container Optimised OS. After a couple of weeks, one of the containers got to a weird state - which broke the backend and I had to restart it manually.

To prevent this from happening in the future, I wanted to create a cron job which would do the same thing (docker restart) every day. However, that is not something I can do in the Container Optimised OS as there is no cron nor a package manager.

Is there a way of periodically restarting containers?

I know it's not an optimal solution, but it would help until I find a proper one.

Also, I've got a health check setup in google cloud. If the health check could run the restart when it detects an issue, that would be nice too.

Ideally, I'd like to implement both the periodical and the healt-check driven restart.

  • The first thing to do is to fix your container. It should not go in an unhealthy state. But it could be long and hard to fix. Restarting a container is not the correct way. It's better to kill the VM. If you have an health check, it will detect the VM out and recreate a new one ( you need a managed/unmanaged instance group for that). The other solution, if y ou serve HTTP traffic and your service is compliant with Cloud Run is to use serverless service, like Cloud Run that run your containers only when required and stop them the rest of the time! – guillaume blaquiere Apr 26 '23 at 09:53
  • 1
    If you have access to the host's Docker socket, you can run cron in a `docker:dind` container and map the host's docker socket into the container. Then you can run `docker restart` of your problematic container from the 'dind' container. – Hans Kilian Apr 26 '23 at 10:26
  • The below link might be useful to you which is related to health checks. https://cloud.google.com/container-optimized-os/docs/how-to/monitoring – Kiran Kotturi Apr 26 '23 at 11:49

0 Answers0