Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker healthcheck #532

Open
CodaBool opened this issue Oct 24, 2024 · 1 comment
Open

Add Docker healthcheck #532

CodaBool opened this issue Oct 24, 2024 · 1 comment

Comments

@CodaBool
Copy link

CodaBool commented Oct 24, 2024

why

Docker healthchecks are minor but a nice to have. Services like AWS ECS make good use of them. The result shows in docker ps. I don't personally use portainer but I know it's common for self-host and it appears like they also make use of it in their UI, related. I personally use them in my selfhost machine with the lazydocker CLI

how

I have experience in this area (contributed to adding healthchecks to other self-host projects immich, cloudflare tunnel, and microbin) and can help contribute. There are generally two approaches people take for something like this:

  1. create a script or endpoint
  2. add a tool, like netcat for basic Docker healthchecks

I recommend option 1 to minimize bloat. You already have curl in the image so just need either add script that can be ran using bash to hit the endpoint. Or if one already exists write a one-liner with curl to hit the endpoint.

example healthcheck in a docker-compose

healthcheck:
  test: curl --fail http://localhost:PORT || exit 1

you can actually add the default healthcheck behavior into the Dockerfile and then people won't have to add extra lines to their docker-compose

Other considerations

  • if your image is not ready for it this can add junk logs
  • if you for some reason switch to a slimmer base image at some point curl/whatever CLI might not exist
  • I think a possible solution might be to connect to rcon since that should always be running. I'm just not sure if you have a rcon client already on the image that can be used (if you do that seems like a clean approach, maybe even having it attempt a console command like /players count or /time to verify the server is running).
  • could probably copy the approach that the most popular minecraft image takes. Which makes a lot of sense since this image isn't a web server (curl might be useless). Their image is also a UDP service with a side RCON service. Here is their Dockerfile code which runs a bash script here
    • EDIT: looking into this further the minecraft image describes here that they have a Golang static binary built just for querying the health of a minecraft server baked into the image. I did a static binary approach for microbin but it's generally an overkill for what healthchecks are. But if your already doing something similar it could work 🤷
@tuetenk0pp
Copy link

related #476

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants