Fernando Benavides
Fernando Benavides

Reputation: 11

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

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

Upvotes: 1

Views: 328

Answers (1)

paltaa
paltaa

Reputation: 3244

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

Upvotes: 1

Related Questions