使用 docker-compose 设置重新启动容器的时间段

使用 docker-compose 设置重新启动容器的时间段

你如何每 60 秒重新启动一次容器服务我尝试过睡眠但它对我来说不起作用:

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

答案1

答案2

我在这里找到了一个非常优雅的解决方案:

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

相关内容