Add a health check to a Docker container running a simple Node.js application.
Question
// app.js
const express = require('express');
const app = express();
// A simple route to return the status of the application
app.get('/health', (req, res) => {
res.status(200).send('OK');
});
// Example main route
app.get('/', (req, res) => {
res.send('Hello, Docker!');
});
// Start the server on port 3000
const port = 3000;
app.listen(port, () => {
console.log(`App is running on http://localhost:${port}`);
});Solution
Step 1: Create a Dockerfile
Step 2: Build and Run the Docker Image

Step 3: Verify the Health Check

Last updated