TimWolla / docker-adminer

Database management in a single PHP file
https://hub.docker.com/_/adminer/
157 stars 69 forks source link

add netcat to provide healthcheck #134

Closed joubertredrat closed 1 year ago

joubertredrat commented 1 year ago

This PR adds netcat to have options to do health check on running container.

Example on terminal

$ nc -vz 127.0.0.1 8080

Example on docker compose based from base into documentation on https://hub.docker.com/_/adminer/:

version: '3.1'

services:

  adminer:
    image: adminer
    restart: always
    ports:
      - 8080:8080
    healthcheck:
      test: ["CMD", "nc", "-vz", "127.0.0.1", "8080"]
      interval: 3s
      timeout: 1s
      retries: 20

  db:
    image: mysql:5.6
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
TimWolla commented 1 year ago

@joubertredrat Thank you for the contribution. I must have missed the notification and I've just seen the PR. I don't have time to look into this for a real review, but I've set me a reminder to look into this. If you don't hear from me within a reasonable time frame, don't be shy to send a ping.

TimWolla commented 1 year ago

Checking whether something responds on port 8080, does not actually mean that Adminer is healthy: It does not guarantee that Adminer will be able to connect to the database.

However even for such a superficial health check, installing an extra executable is not required. The container necessarily contains PHP and that can be used to perform a health check, that is even more meaningful by actually checking whether the output looks reasonable:

php -r 'exit(strpos(file_get_contents("http://localhost:8080/"), "Adminer") !== false ? 0 : 1);'

This will exit with 0 (Success) if the HTTP response contains “Adminer” and with 1 (Failure) if it does not.