0

I built a docker image like that:
Dockerfile:

FROM busybox
WORKDIR /
COPY healthcheck.sh .
RUN chmod +x healthcheck.sh
HEALTHCHECK --start-period=1s --interval=2s --timeout=3s --retries=3 CMD /healthcheck.sh || exit 1
CMD while true; do $(echo date); sleep 10; done

helthcheck.sh:

#!/bin/sh
if [ $HOSTNAME ]; then
  echo "OK"
  exit 0
else
  echo "FAIL"
  exit 1
fi

My goal is to send an "OK" or "FAIL" in the container's log stream along with a date.

Is there a way to achieve that? "log-driver": "awslogs"

Thanks!

Vasyl Herman
  • 414
  • 2
  • 11
  • Which docker logging driver are you using? Usually any text printed to stdout should go to the logs – Sergio Santiago Apr 24 '22 at 19:30
  • I am planning to use awslogs. now I am testing on a fresh Ubuntu 20.04 and newly installed docker via `curl -fsSL https://get.docker.com | bash` – Vasyl Herman Apr 24 '22 at 19:41

1 Answers1

0

You can use AWS cloud watch log driver With this configuration, anything sent stdout will be shipped to AWS.

The issue is that the healthcheck runs in a different process than your main process, so it's hard to write to the main process' stdout.

here there is a hacky solution to circumvent this

Sergio Santiago
  • 1,316
  • 1
  • 11
  • 19