factoriotools / factorio-docker

Factorio headless server in a Docker container
https://hub.docker.com/r/factoriotools/factorio/
MIT License
1.08k stars 243 forks source link

Add Docker healthcheck #532

Open CodaBool opened 1 month ago

CodaBool commented 1 month ago

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

tuetenk0pp commented 1 month ago

related #476