What is the best way to restart a docker container when another one is updated?

253 Views Asked by At

I have an OpenHAB container and a Mosquitto container; what is the best way to restart the OpenHAB if Mosquitto is updated? Upon restarting or updating the Mosquitto, the OpenHAB (and home assistant) do not reconnect to the MQTT

1

There are 1 best solutions below

2
paltaa On

It is better to set a healthcheck for your failing containers. So, in the case that the mosquitto server is updated and they fail to connect, they can restart. For example:

version: '3.4'
services:
  web:
    image: very-simple-web
    build:
      context: ./
      dockerfile: Dockerfile
    restart: unless-stopped
    ports:
      - "80:80"
    healthcheck:
      test: curl --fail http://localhost || exit 1
      interval: 60s
      retries: 5
      start_period: 20s
      timeout: 10s

In this case very-simple-web, will fail if a request to http://localhost and restart until the healtcheck succeeds. So, you should add healthchecks for openhab and home assistant