Junior — Middle
Have you configured automatic scalability of services in Docker Swarm?
sobes.tech AI
Answer from AI
Yes, automatic scalability in Docker Swarm can be configured using commands and configurations that allow changing the number of service replicas depending on the load.
Main approaches:
- Using built-in commands for scaling:
docker service scale my_service=5
-
Automation through external monitoring and orchestration tools (e.g., Prometheus + Alertmanager + scripts), which trigger scaling commands upon reaching certain metrics.
-
Using Docker Swarm integrated into CI/CD, where the number of replicas automatically changes when load changes or code is updated.
Example of a simple script for service scaling:
#!/bin/bash
current_replicas=$(docker service ls --filter name=my_service --format "{{.Replicas}}" | cut -d/ -f1)
if [ "$current_replicas" -lt 5 ]; then
docker service scale my_service=5
fi
Thus, automatic scalability in Docker Swarm requires either external monitoring and trigger tools or manual execution of scaling commands.