How to do a healthcheck in a Docker image without curl?

There is a tendency to strip docker images from wget and curl. Luckily, perl is still available. If you have trouble configuring spring boot healthcheck, think of perl and its IO::Socket module shipped with perl core:

FROM openjdk:11-jre-slim
HEALTHCHECK --start-period=10s --timeout=3s --retries=5 \
 CMD perl -e "use IO::Socket; $sock = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => 'localhost', PeerPort => '8888') or die $@; $sock->autoflush(1); print $sock 'GET /actuator/health HTTP/1.1' . chr(0x0a) . chr(0x0d) . 'Host: localhost:8888' . chr(0x0a) . chr(0x0d) . 'Connection: close' . chr(0x0a) . chr(0x0d) . chr(0x0a) . chr(0x0d); while (my $line = $sock->getline ) { if ($line =~ /UP/) {exit;} }; close $sock; exit 1;"