Skip to content

Latest commit

 

History

History
53 lines (34 loc) · 1.46 KB

04-docker-compose.md

File metadata and controls

53 lines (34 loc) · 1.46 KB

Docker compose

Using replicas

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.

Manual replicas

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