8

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 Answers 2

7

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 
2
  • 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? Commented Jul 20, 2022 at 22:50
  • What kind of answer is this? I already have a healthcheck on a container, that doesn't restart the container. Commented Aug 27, 2022 at 17:46
8

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 

You must log in to answer this question.