Table of Contents
- Verify Cluster Status
- Create Your First Service
- Inspect Tasks and Service Details
- View Service Logs
- Self-Healing Demonstration
- Remove the Service
- Scale Services
- Rolling Updates
- Rollback
- Quick Command Reference
1. Verify Cluster Status
Ensure your 6-node Swarm is healthy and managers/workers are all Ready: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 thehttpd:alpine image on port 80:
3. Inspect Tasks and Service Details
List the tasks (containers) forfirst-service:
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.- On a worker, find and remove the container:
- 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
b. Scale Up to Five Replicas
c. Scale Down to Three Replicas
8. Rolling Updates
Perform seamless image upgrades without stopping traffic.- View current image:
- Update to a new tag (e.g.,
httpd:2): - 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
| Operation | Command |
|---|---|
| Verify cluster | docker node ls |
| Create service | docker service create --name <svc> -p 80:80 <image> |
| List services | docker service ls |
| Inspect service | docker service inspect <svc> --pretty |
| View service tasks | docker service ps <svc> |
| Stream logs | docker service logs <svc> |
| Remove service | docker service rm <svc> |
| Scale service | docker service update --replicas <n> <svc> |
| Rolling update | docker service update --image <image:tag> <svc> |
| Rollback | docker service update --rollback <svc> |