Skip to main content
Docker Swarm lets you manage containerized applications as services rather than individual containers. A service in Swarm mode ensures your desired state—replicas, load balancing, rolling updates, and self-healing—are always maintained.

Table of Contents

  1. Verify Cluster Status
  2. Create Your First Service
  3. Inspect Tasks and Service Details
  4. View Service Logs
  5. Self-Healing Demonstration
  6. Remove the Service
  7. Scale Services
  8. Rolling Updates
  9. Rollback
  10. Quick Command Reference

1. Verify Cluster Status

Ensure your 6-node Swarm is healthy and managers/workers are all Ready:
Sample output:
Always confirm that at least one manager node is in Leader status before proceeding.

2. Create Your First Service

Deploy a simple HTTP server using the httpd:alpine image on port 80:
Verify that the service is up:
Expected output:

3. Inspect Tasks and Service Details

List the tasks (containers) for first-service:
For a detailed, human-friendly overview:
Key excerpt:

4. View Service Logs

Stream logs to troubleshoot or verify startup:

5. Self-Healing Demonstration

Swarm automatically replaces failed tasks to maintain the desired replica count.
  1. On a worker, find and remove the container:
  2. Back on a manager, confirm Swarm recreated it:
Swarm will detect that the replica count is below the desired state and launch a new task immediately.

6. Remove the Service

Clean up by removing the service and all its tasks:

7. Scale Services

Run multiple replicas behind Swarm’s built-in load balancer to ensure zero downtime.

a. Create a Service with Three Replicas

Verify:

b. Scale Up to Five Replicas

c. Scale Down to Three Replicas


8. Rolling Updates

Perform seamless image upgrades without stopping traffic.
  1. View current image:
  2. Update to a new tag (e.g., httpd:2):
  3. Monitor rollout:
During rolling updates, verify your application’s health checks to avoid cascading failures.

9. Rollback

If an update misbehaves, revert immediately:

10. Quick Command Reference


Watch Video