3

How to restart a container with every interval timeout in docker-compose.yml by an option?

This is my simplified docker-compose.yml:

version: '3'

services:
  ivms_app:
      build: .
      image: an_image
      container_name: app_name
      restart: unless-stopped

      ports:
        - "9001:9001"

I have set the restart option with unless-stopped attribute. But I want an option for restarting a container with every interval timeout in docker-compose.yml like this:

interval_restart: 30 # 30 minutes

Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
  • I don't think there is a way to do this kind of configuration in the `docker-compose.yml` file. Have you tried anything else? For example a `cron` job which will run a script every 30 minutes that does what you want? Related: [How to restart a single container with docker-compose](https://stackoverflow.com/questions/31466428/how-to-restart-a-single-container-with-docker-compose). – tgogos Nov 26 '18 at 11:14
  • 1
    I'm curious that under what context do you want to have this behavior? – Siyu Nov 26 '18 at 12:25
  • 1
    This question seems similar to what is being asked here: https://serverfault.com/questions/1003348/set-time-period-to-restart-a-container-with-docker-compose, the answer might be what you are looking for @Benyamin Jafari. – Prabhatika Vij Jun 21 '22 at 12:33
  • 1
    @PrabhatikaVij Thanks for mentioning the link. I don't know how I solved the problem in 2018 :-D. The mentioned post was written in 2020 that's why I hadn't seen that. So sounds great for others' issue – Benyamin Jafari Jun 21 '22 at 13:10

0 Answers0