Topics In Demand
Notification
New

No notification found.

Using Docker APIs to Perform Health Checks
Using Docker APIs to Perform Health Checks

July 4, 2022

251

0


Listen to this article



An important aspect of creating and maintaining your production environment is performing health checks.

These are useful to ensure flawless business continuity, and make it easier to be vigilant, acting as early warning systems. These systems monitor and trigger alerts at the right time, giving us the time needed to come up with solutions and react appropriately.

In the modern era of microservices, most of the industry has moved to Docker-based deployments for its production environment. This enables teams to provide the horizontal scaling needed, among numerous other advantages, as compared to traditional deployment methods.

But what makes Docker-based APIs so useful here, especially in situations where a service or an application needs no port to run?

The Problem — Performing Health Checks on Certain Types of Microservices

There are two types of microservices:

  1. One running using some port that could be used to check the health status of the running application process.
  2. The other is scheduler services — that run at a given time of the day and perform a specific task. These do not require a port to run.

In this context, how do we perform health checks?

>> The Solution — Use Docker APIs

The answer lies in using Docker APIs for conducting health checks.

Here are the 3 simple steps to configure Docker APIs for conducting health checks:

Step 1. Enable Docker APIs

Enable Docker API using the code below:

vi /lib/systemd/system/docker.service

Then, add the following line of code to your file:

ExecStart=/usr/bin/dockerd -H fd:// -H=tcp://0.0.0.0:5555 containerd=/run/containerd/containerd.sock $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_ADD_RUNTIMES

Graphical user interface, text

Description automatically generated

 

Step 2. Restart Docker service

After enabling Docker API in the previous step, shut down the Docker service and restart the same.

Step 3. Check availability of Docker API

After performing a service restart in step 2, we should have the Docker API available at the following path:

<hostname>:<port as configured above>/containers/{id or name of container}/top

Please note — We are using Docker version 18.09.9-ce, build 039a7df for this.

Verify functionality of Docker API

Looking at the container we created (named “test”), we get a 200 status code in response, if the Docker container is running alright.
 

Graphical user interface, application, email

Description automatically generated

 

This technique lets us get the health status of all running containers, based on their container names irrespective of whether or not an application is using a port.

In case you are using a proxy like ‘Nginx’ & ‘haproxy’, you must configure these Docker APIs in that proxy service to enable health checks to be performed externally.

Please note — in our example, the name of the container is also the name of the application.

Author — Gautam Singh Malik, DLT Labs

About the Author: Gautam is an IT practitioner skilled in Node.js, Linux, Core Java, Shell Scripting, Elasticsearch, Graph QL, JavaScript, and Neo 4.

References

https://docs.docker.com/engine/api/v1.25/#operation/ContainerTop


That the contents of third-party articles/blogs published here on the website, and the interpretation of all information in the article/blogs such as data, maps, numbers, opinions etc. displayed in the article/blogs and views or the opinions expressed within the content are solely of the author's; and do not reflect the opinions and beliefs of NASSCOM or its affiliates in any manner. NASSCOM does not take any liability w.r.t. content in any manner and will not be liable in any manner whatsoever for any kind of liability arising out of any act, error or omission. The contents of third-party article/blogs published, are provided solely as convenience; and the presence of these articles/blogs should not, under any circumstances, be considered as an endorsement of the contents by NASSCOM in any manner; and if you chose to access these articles/blogs , you do so at your own risk.


DLT Labs™ is a global leader in the development and delivery of enterprise blockchain technologies and solutions, as well as a pioneer in the creation and implementation of standards for application development. With a deep track record in innovation and one of the world's largest pools of highly experienced blockchain experts, DLT Labs™ enables the transformation and innovation of complex multi-stakeholder processes.

© Copyright nasscom. All Rights Reserved.