Docker Swarm Overview

Structure of Docker Swarm

Docker Swarm is organized into the following hierarchy:

  • Stacks: Groups of multiple services.
  • Services: Manage and scale containers.
  • Containers: Individual units that are managed by services.

If a container crashes, the service ensures it is restarted immediately.

Zero-Downtime Deployment

Docker Swarm enables zero-downtime deployments by:

  1. Starting a new container alongside the old one during deployment.
  2. Replacing the old container only after the new one passes a health check.

Health Check

The health check verifies that the new container responds correctly, typically with a status 200.

Example Health Check:

curl --fail http://localhost:3000/meta || exit 1

This command ensures the endpoint /meta returns a 200 status.

  • Health checks are run initially and periodically.
  • If a health check fails after prolonged runtime, the container is restarted.
  • Logs for health checks are available in DeployParty under the logs section.

Without Health Checks

Without a health check:

  • Both old and new containers would lack a "healthy" or "unhealthy" status.
  • Containers would be swapped immediately, risking service downtime.

Benefits of Docker Swarm

Docker Swarm ensures:

  • Containers are always available during deployments.
  • Failed containers are restarted automatically, minimizing downtime. By leveraging Docker Swarm's service orchestration and health checks, applications maintain high availability and reliability.