🐛 Bug Report: Health check fails on Docker
Describe the bug
Health check fails on Docker
Steps to reproduce the bug
{ "Status": "starting", "FailingStreak": 1, "Log": [ { "Start": "2024-05-20T14:01:44.00930286+02:00", "End": "2024-05-20T14:01:44.063915771+02:00", "ExitCode": 1, "Output": "wget: can't connect to remote host: Connection refused\n" }, [...]
Solution
The health check in the Dockerfile points wget to localhost which can not be resolved. Please add a /etc/hosts file (127.0.0.1 localhost).
Context
The image used was from quay.io
Related to https://github.com/redlib-org/redlib/issues/73
The hosts file is correct. The problem is caused by the server only listening on IPv4 by default. Since Docker now supports IPv6, IPv6 has precedence over v4 so localhost resolves to [::1] before resolving to 127.0.0.1 causing wget to error out.
In my opinion, the best way to fix this would be to start the server on both IPv4 and IPv6 by default, unless there are some problems (but there shouldn't be any).
As a quick fix, depending on your setup, you can either:
- run the container with the flag
--sysctl=net.ipv6.conf.all.disable_ipv6=1in yourdocker runcommand to disable IPv6 in the container complitely - modify the
healthcheckin thedocker-compose.yamlfile by replacinglocalhostwith127.0.0.1
This breaks the container if you're trying to use this on a v4-only host, and there's no way to set the sysctl in docker-compose in a way that works.
sysctls:
- net.ipv6.conf.all.disable_ipv6=1
returns
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: open /proc/sys/net/ipv6/conf/all/disable_ipv6: no such file or directory: unknown
(At least I think I did it right, I keep getting mixed results on how to set it.)
Without, the container just complains there's no v6:
docker[338686]: redlib | thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-0.14.29/src/server/server.rs:81:>
docker[338686]: redlib | error binding to [::]:8080: error creating server listener: Address family not supported by protocol (os error 97)
docker[338686]: redlib | note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
An exposed option in the .env might help in this situation.
You're right, I didn't think of that. As soon as I can I'll add the env variable (it won't be hard since it already handles it as a command line argument), test it, and make a PR.
For now, you can either downgrade to an older version that doesn't listen on IPv6 (<= 0.34.0) or build the container yourself and add the argument -a 0.0.0.0 in the Dockerfile
I built the container once I realized what changed in the pull request and it's just hunky dory. Looking forward to the image update though.
Bit late to this issue, but when I added -a 0.0.0.0 I got invalid argument error in redlib, is there another way to fix this?
Any update on health check fix? I would like it to make it work, because I use Sablier which needs to know if container is healthy or not