Docker Swarm is a native clustering and orchestration tool provided by Docker. It allows multiple Docker nodes to be grouped together to form a cluster, enabling the deployment and management of applications across multiple containers and machines. Unlike standalone Docker containers or Docker Compose, Docker Swarm introduces orchestration capabilities such as scaling, load balancing, and self-healing.
In this experiment, we implement a real-world multi-container application using Docker Swarm. The application consists of a WordPress service connected to a MySQL database. The WordPress service is deployed with multiple replicas to demonstrate scaling and load balancing, while the MySQL service provides persistent data storage.
This experiment highlights the transition from simple container execution to production-level orchestration concepts.
The objectives of this experiment are:
Before performing this experiment, the following requirements must be satisfied:
Docker Swarm is used to manage a cluster of Docker nodes. It introduces the concept of services instead of individual containers.
A service defines how containers should run, including image, replicas, and networking.
Replicas represent the number of container instances running for a service.
Swarm automatically distributes incoming requests across all replicas.
If a container fails, Swarm automatically replaces it to maintain the desired state.
The system consists of:
Swarm provides:
docker swarm init
version: "3.8"
services:
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress
volumes:
- db_data:/var/lib/mysql
wordpress:
image: wordpress:latest
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: root
deploy:
replicas: 3
volumes:
db_data:
docker stack deploy -c docker-compose.yml wpstack
docker service ls
docker ps
Open browser: http://localhost:8080
docker kill
docker service ps wpstack_wordpress
docker stack rm wpstack
Docker Swarm provides an efficient and simple way to orchestrate containerized applications. Through this experiment, we demonstrated scaling, load balancing, and self-healing. This makes Docker Swarm suitable for learning orchestration and deploying small to medium applications.