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

6
  • 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. Commented Nov 26, 2018 at 11:14
  • 1
    I'm curious that under what context do you want to have this behavior? Commented Nov 26, 2018 at 12:25
  • 1
    This question seems similar to what is being asked here: serverfault.com/questions/1003348/…, the answer might be what you are looking for @Benyamin Jafari. Commented Jun 21, 2022 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 Commented Jun 21, 2022 at 13:10
  • 1
    @dragon at that time (2018) I was looking for an attribute in docker-compose to restart a container every X minutes! BTW, thank you for sharing about the restart policy in docker compose I didn't know about that. :-D Commented Sep 11, 2023 at 14:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.