Skip to content

Add a dynamic address resolution to the Docker healthcheck

The way the Docker HEALTHCHECK is currently performed is to run against localhost without any means of configuring a different address. Unfortunately, if you have conduit listen on an address such as 0.0.0.0, localhost can potentially be an invalid target and you end up with this:

~ $ ./healthcheck.sh 
Connecting to localhost:6167 ([::1]:6167)
wget: can't connect to remote host: Connection refused
Connecting to localhost:6167 ([::1]:6167)
wget: can't connect to remote host: Connection refused

and

$ docker ps | grep conduit
0dc8e8dc7622   d4aba9702de0   "/srv/conduit/conduit"   4 days ago         Up 4 days (unhealthy)          6167/tcp

In order to work around this problem I've extended the healthcheck.sh script with a dynamic resolution of the address that's in use by conduit, defaulting to CONDUIT_ADDRESS and, if not set, to resolving the address from the process output (same as for the CONDUIT_PORT check earlier in the script).

The results are now:

$ echo $CONDUIT_ADDRESS
0.0.0.0
$ ss -tlpn | awk -F ' {3,}|:' '/conduit/ { print $3 }'
0.0.0.0
$ ./healthcheck.sh 
Connecting to 0.0.0.0:6167 (0.0.0.0:6167)
remote file exists
~ $ echo $?
0

  • I ran cargo fmt and cargo test
  • I agree to release my code and all other changes of this MR under the Apache-2.0 license

Merge request reports