AVENTER-UG / docker-matrix

docker image for matrix.org
https://riot.im/app/#/room/#dockermatrix:matrix.aventer.biz
GNU General Public License v2.0
93 stars 19 forks source link

Healthcheck for docker-compose #37

Closed motey closed 5 years ago

motey commented 5 years ago

i had the problem with docker compose, that the Postgres DB wasnt ready early enough sometimes and the synapse docker failed boot due to the not reachable DB. The usual way of creating a simple healtcheck with a curl-command wasnt working, because curl isn't installed in the docker-matrix image.

I wrote a one liner in python to do the healtcheck:

python3 -c "import urllib.request;exec('try:\n\turllib.request.urlopen(\'http://127.0.0.1:8008\')\nexcept:\n\texit(1)')"

With that we can persuade the matrix-docker container to retry to connect to the db and the database has some more time to bootup

This is a simplified extract from my docker-compose file as an example

version: "2.1"
services:
  postgres:
    image: postgres:11
    restart: unless-stopped
    networks:
      - default
    volumes:
      -/whatever/data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=synapse
      - POSTGRES_PASSWORD=xxxx
      - POSTGRES_USER=synapse
    healthcheck:
      test: "pg_isready -h localhost -p 5432 -q -U postgres"
      interval: 3s
      timeout: 5s
      retries: 5

  synapse:
    image: avhost/docker-matrix:v1.1.0
    restart: on-failure
    depends_on:
      - postgres
    healthcheck:
      test: python3 -c "import urllib.request;exec('try:\n\turllib.request.urlopen(\'http://127.0.0.1:8008\')\nexcept:\n\texit(1)')"
      interval: 1m
      timeout: 10s
      retries: 3
    networks:
      - web
      - default
[...]

This is just a documentation issue, if somebody runs in the same problem