Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose restart interval

I have a docker-compose.yml file with a following:

services:
  kafka_listener:
    build: .
    command: bundle exec ./kafka foreground
    restart: always
  # other services

Then I start containers with: docker-compose up -d

On my amazon instance kafka-server (for example) fails to start sometimes, so ./kafka foregound script fails. When typing docker ps I see a message: Restarting (1) 11 minutes ago. I thought docker should restart failed container instantly, but it seems it doesn't. After all, container has been restarted in about 30 minutes since first failed attempt.

Is there any way to tell Docker-Compose to restart container instantly after failure?

like image 962
nattfodd Avatar asked Mar 27 '17 07:03

nattfodd


People also ask

Does Docker compose auto restart?

Like the restart Docker command, Docker Compose includes the restart property to restart containers automatically.

What is the restart policy in Docker compose?

A restart policy only takes effect after a container starts successfully. In this case, starting successfully means that the container is up for at least 10 seconds and Docker has started monitoring it. This prevents a container which does not start at all from going into a restart loop.

How long does docker take to restart?

There's a timeout, which is 10 seconds by default for each container. If even one of your containers does not respond to SIGTERM signals, Docker will wait for 10 seconds at least.


1 Answers

You can use this policy :

  • on-failure

The on-failure policy is a bit interesting as it allows you to tell Docker to restart a container if the exit code indicates error but not if the exit code indicates success. You can also specify a maximum number of times Docker will automatically restart the container. like on-failure:3 It will retry 3 times.

  • unless-stopped

The unless-stopped restart policy behaves the same as always with one exception. When a container is stopped and the server is rebooted or the Docker service is restarted, the container will not be restarted.

Hope this will help you in this problem.

Thank you!

like image 155
chintan thakar Avatar answered Sep 17 '22 23:09

chintan thakar