- Back to README
- Heroku
- DigitalOcean App Platform
- Fly.io
- Docker Compose
This setup has 2 replicas of the app:
export IMAGE="analythium/python-shiny-lb:0.1"
# export IMAGE="analythium/r-shiny-lb:0.1"
docker-compose up -d
## follow the logs
docker-compose logs -f
## shut down
docker-compose down --remove-orphans
The setup fails because the standard load balancing for scaling services is round robin, that is not sticky.
The Caddy load balancing setting has no effect, because Docker is still adding its own load balancing behind Caddy.
We can add sticky sessions using Caddy for load balancing.
The docker-compose-lb.yml
file uses anchors and extensions because we deploy the same image multiple times so that we can load balance between the replicas.
Try lb_policy random
(default) to see the test fail. lb_policy ip_hash
will succeed:
export LB_POLICY="ip_hash"
# export LB_POLICY="random"
export IMAGE="analythium/python-shiny-lb:0.1"
# export IMAGE="analythium/r-shiny-lb:0.1"
docker-compose -f docker-compose-lb.yml up -d
## follow the logs
docker-compose logs -f
## shut down
docker-compose down --remove-orphans