Docs / Containers & Docker / Docker Health Checks and Restart Policies

Docker Health Checks and Restart Policies

By Admin · Mar 1, 2026 · Updated Apr 23, 2026 · 4 views · 3 min read

Docker Health Checks and Restart Policies is a common requirement for VPS administrators. This guide provides practical instructions that you can follow on Ubuntu 22.04/24.04 or Debian 12, though most steps apply to other distributions as well.

Prerequisites

  • Root or sudo access to the server
  • Basic familiarity with the Linux command line
  • Docker Engine 24.0+ installed
  • Docker Compose v2 installed
  • A registered domain name (for public-facing services)

Creating the Docker Compose File

When scaling this setup, consider vertical scaling (adding more RAM/CPU) first, as it's simpler to implement. Horizontal scaling adds complexity but may be necessary for high-traffic applications.


# docker-compose.yml
version: '3.8'
services:
  app:
    image: health-checks:latest
    restart: unless-stopped
    ports:
      - "8080:8080"
    volumes:
      - app_data:/data
    environment:
      - NODE_ENV=production
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  app_data:

Each line in the configuration serves a specific purpose. The comments explain the reasoning behind each setting, making it easier to customize for your specific use case.

Important Notes

If you encounter issues during setup, check the system logs first. Most problems can be diagnosed by examining the output of journalctl or the application-specific log files in /var/log/.

Building the Container Image

Regular maintenance is essential for keeping your health-checks installation running smoothly. Schedule periodic reviews of log files, disk usage, and security updates to prevent issues before they occur.


# Multi-stage Dockerfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/index.js"]

Make sure to restart the service after applying these changes. Some settings require a full restart rather than a reload to take effect.

Advanced Settings

The restart component plays a crucial role in the overall architecture. Understanding how it interacts with health-checks will help you make better configuration decisions.

  • Monitor disk space usage and set up alerts
  • Keep your system packages updated regularly
  • Enable automatic security updates for critical patches

Common Issues and Solutions

  • Slow performance: Check for disk I/O bottlenecks with iostat -x 1 and network issues with mtr. Review application logs for slow queries or requests.
  • Connection timeout: Verify your firewall rules allow traffic on the required ports. Use ss -tlnp to confirm the service is listening on the expected port.
  • Permission denied errors: Ensure files and directories have the correct ownership. Use chown -R to fix ownership and chmod for permissions.

Summary

You've successfully configured health-checks on your VPS. Remember to monitor performance, keep your software updated, and maintain regular backups. If you run into issues, consult the official documentation or open a support ticket for assistance.

Was this article helpful?