Middle
What is your experience with Docker Swarm?
sobes.tech AI
Answer from AI
Docker Swarm was actively used for orchestrating containerized applications in small and medium projects.
Main tasks solved with Swarm:
- Deployment and scaling: Deployed service stacks (web, app, db) and horizontally scaled stateless components.
- Configuration management: Used Docker secrets and configs for secure storage of sensitive data and service configuration management.
- Service updates: Conducted rolling updates of services with control over the percentage of parallel updates and delay between updates.
- Monitoring: Integrated Swarm with external monitoring systems (e.g., Prometheus and Grafana), collecting container and node metrics.
- Logging: Set up centralized logging (e.g., using ELK Stack), collecting logs from all containers in the cluster.
- Network: Used overlay network for service interaction and ingress network for external access.
Example of stack deployment:
# docker-compose.yml for Docker Swarm
version: '3.8'
services:
web:
image: nginx:latest
ports:
- "80:80"
deploy:
replicas: 3
update_config:
parallelism: 1
delay: 10s
restart_policy:
condition: on-failure
networks:
- app_overlay
app:
image: myapp:latest
deploy:
replicas: 5
restart_policy:
condition: on-failure
networks:
- app_overlay
- db_overlay
secrets:
- db_password
configs:
- app_config
db:
image: postgres:latest
volumes:
- db_data:/var/lib/postgresql/data
deploy:
replicas: 1 # Stateful service
restart_policy:
condition: on-failure
networks:
- db_overlay
secrets:
- db_password
volumes:
db_data:
networks:
app_overlay:
driver: overlay
db_overlay:
driver: overlay
secrets:
db_password:
file: ./db_password.txt
configs:
app_config:
file: ./app.conf
Command line:
# Initialize swarm
docker swarm init --advertise-addr <MANAGER_IP>
# Join worker node
docker swarm join --token <TOKEN> <MANAGER_IP>:2377
# Deploy stack
docker stack deploy -c docker-compose.yml my-stack
# Scale service
docker service scale my-stack_app=10
# Update service
docker service update --image myapp:new-version my-stack_app
# View services
docker service ls
# View tasks (service instances)
docker service ps my-stack_app
Compared to Snowflake, Docker Swarm is simpler to set up for initial clusters and suitable for projects that do not require complex orchestration scenarios or high cluster fault tolerance (compared to Kubernetes HA). However, for large, complex, and critical infrastructures, Kubernetes is a more powerful and flexible solution.