3

how would you do to restart the container service every 60 seconds I tried sleep but it doesn't work for me:

spark:
    image: jaegertracing/spark-dependencies
    environment:
      - STORAGE=elasticsearch
      - ES_NODES=http://localhost:9200
    command: [ /bin/bash -c sleep 20 ]
    restart: always
    networks:
      - elastic-jaeger

2 Answers2

4

you could use healthchecks combined with restart: always

healthcheck:
  test: curl -sS http://127.0.0.1 || exit 1
  interval: 5s
  timeout: 10s
  retries: 3
invad0r
  • 171
  • 3
  • Am I wrong in assuming, the test will always return "1"; as in failure? What if there is an actual web service at 127.0.0.1? – ZaxLofful Jul 20 '22 at 22:50
  • What kind of answer is this? I already have a healthcheck on a container, that doesn't restart the container. – Daniel Katz Aug 27 '22 at 17:46
0

I have found a very elegant solution here:

https://gist.github.com/kizzx2/782b500a81ce46b889903b1f80353f21

version: '3'
services:
  app:
    image: nginx:alpine
    ports: ["80:80"]
    restart: unless-stopped

  restarter:
    image: docker
    volumes: ["/var/run/docker.sock:/var/run/docker.sock"]
    command: ["/bin/sh", "-c", "while true; do sleep 86400; docker restart app_app_1; done"]
    restart: unless-stopped
Daniel Katz
  • 101
  • 1