phpmyadmin / docker

Docker container for phpMyAdmin
https://hub.docker.com/_/phpmyadmin
GNU General Public License v3.0
675 stars 455 forks source link

add netcat to provide healthcheck #396

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

root@phpmyadmin:/var/www/html# nc -vz 127.0.0.1 80
Connection to 127.0.0.1 80 port [tcp/*] succeeded!

Example on docker compose using docker-compose.yml from this project as base:

phpmyadmin:
    image: phpmyadmin
    container_name: phpmyadmin
    environment:
     - PMA_ARBITRARY=1
    restart: always
    ports:
     - 8080:80
    volumes:
     - /sessions
    healthcheck:
        test: ["CMD", "nc", "-vz", "127.0.0.1", "80"]
        interval: 3s
        timeout: 1s
        retries: 20
ibennetch commented 1 year ago

https://github.com/renatomefi/php-fpm-healthcheck looks promising for the fpm variant (I'm not asking @joubertredrat to implement it, just discussing in one central place).

ibennetch commented 1 year ago

This looks good to me, any other input from the development team?

joubertredrat commented 1 year ago

@williamdes I agree with you, you can use curl as health check too, but, the problem with curl and the reason that I don't like to use curl is that nc check for open and listening port, curl does a request and depending on the web server running, you can pollute the logs, as example below, that I'm using curl as health check. Using nc you don't have this problem.

matomo-protecttrackid-devbox-matomo1-1  | [Wed Feb  8 15:26:49 2023] 127.0.0.1:36145 Closing
matomo-protecttrackid-devbox-matomo1-1  | [Wed Feb  8 15:26:52 2023] 127.0.0.1:44445 Accepted
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:26:49 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:26:53 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:26:56 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:26:59 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:02 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-matomo1-1  | [Wed Feb  8 15:26:52 2023] 127.0.0.1:44445 Closed without sending a request; it was probably just an unused speculative preconnection
matomo-protecttrackid-devbox-matomo1-1  | [Wed Feb  8 15:26:52 2023] 127.0.0.1:44445 Closing
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:05 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:09 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:12 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:15 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:18 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-matomo1-1  | [Wed Feb  8 15:26:55 2023] 127.0.0.1:41011 Accepted
matomo-protecttrackid-devbox-matomo1-1  | [Wed Feb  8 15:26:55 2023] 127.0.0.1:41011 Closed without sending a request; it was probably just an unused speculative preconnection
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:22 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:25 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-matomo1-1  | [Wed Feb  8 15:26:55 2023] 127.0.0.1:41011 Closing
matomo-protecttrackid-devbox-matomo1-1  | [Wed Feb  8 15:26:58 2023] 127.0.0.1:41765 Accepted
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:28 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
matomo-protecttrackid-devbox-pma-1      | 127.0.0.1 - - [08/Feb/2023:15:27:32 +0000] "GET / HTTP/1.1" 200 140777 "-" "curl/7.74.0"
ibennetch commented 1 year ago

While your reasoning for wanting to use netcat over curl makes sense and I know many people like to have healthchecks available, the policy of the official Docker library group to not want healthchecks means we are unlikely to directly implement this.

However, I'd be open to the idea of posting or maintaining documentation about how to implement it as a derivative of the official Docker images, perhaps a Wiki page with a Dockerfile or something, it seems adding another layer like that wouldn't be too difficult, but I'd have to test that a bit.

joubertredrat commented 1 year ago

Okay guys, thanks

williamdes commented 1 year ago

@williamdes I agree with you, you can use curl as health check too, but, the problem with curl and the reason that I don't like to use curl is that nc check for open and listening port, curl does a request and depending on the web server running, you can pollute the logs, as example below, that I'm using curl as health check. Using nc you don't have this problem.

I agree too, it creates a lot of logs and we should probably provide a ping endpoint or silence some files from the logs.