Skip to main content

Health-Checking

Metadata

This task is complementary to the lectures and lists tasks and information for the in-lesson tasks.

Prerequisites

You must have completed bites/docker-compose. It is also good if you have finished bites/rest-assured

Choose project

Pick any of your existing docker projects. If you do not have one at this point something went terribly wrong... go to echo-server to get an image to play with.

HEALTHCHECK

You can read a good article about docker health checks on medium.

Add a HEALTHCHECK to your Dockerfile (or if you feel savvy, add it to docker-compose.yml).

HEALTHCHECK --interval=10s --timeout=10s --start-period=10s --retries=3 \
CMD curl --fail http://url-from-your-app || exit 1

Run the test

Start the container in any way you fancy and see if your health check works!

docker container ls will show you the status of the container.

Brick it

HEALTHCHECK --interval=10s --timeout=10s --start-period=10s --retries=3 \
CMD curl --fail http://INVALIDURLπŸ’£ || exit 1

Run the health check broken and see how the container gets sick.

Smoke Test

This pattern can also be used for simple integration tests 🧠

Start your containers as daemons

I won't say more than: docker-compose up -d

Curl an URL yourself

Run a cURL or a Postman request.

I will not provide an example here, go back to the very first task if you do not remember this basic.

Terminate

docker-compose down

🧠

This series of commands can also be ran in GitHub Actions... Of course, it is recommended to use a bit more elaborate solution than one cURL command 😊


echo-server

ealen/echo-server is a docker image that just sends back what you send it. Use that image for the exercise.

Note: You will need to use image instead of build in the docker-compose.yml.